Skip to content

Instantly share code, notes, and snippets.

@philipszdavido
Last active November 14, 2017 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philipszdavido/c69ccda78ba8f8b1af5e7eeb53e56045 to your computer and use it in GitHub Desktop.
Save philipszdavido/c69ccda78ba8f8b1af5e7eeb53e56045 to your computer and use it in GitHub Desktop.
<?php namespace Console;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Author: Chidume Nnamdi <kurtwanger40@gmail.com>
*/
class Command extends SymfonyCommand
{
public function __construct()
{
parent::__construct();
}
protected function greetUser(InputInterface $input, OutputInterface $output)
{
// outputs multiple lines to the console (adding "\n" at the end of each line)
$output -> writeln([
'====**** User Greetings Console App ****====',
'==========================================',
'',
]);
// outputs a message without adding a "\n" at the end of the line
$output -> write($this -> getGreeting() .', '. $input -> getArgument('username'));
}
private function getGreeting()
{
/* This sets the $time variable to the current hour in the 24 hour clock format */
$time = date("H");
/* Set the $timezone variable to become the current timezone */
$timezone = date("e");
/* If the time is less than 1200 hours, show good morning */
if ($time < "12") {
return "Good morning";
} else
/* If the time is grater than or equal to 1200 hours, but less than 1700 hours, so good afternoon */
if ($time >= "12" && $time < "17") {
return "Good afternoon";
} else
/* Should the time be between or equal to 1700 and 1900 hours, show good evening */
if ($time >= "17" && $time < "19") {
return "Good evening";
} else
/* Finally, show good night if the time is greater than or equal to 1900 hours */
if ($time >= "19") {
return "Good night";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment