-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathTimeCommand.php
66 lines (53 loc) · 2.05 KB
/
TimeCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/*
* This file is part of the SDPHP event-dispatcher-test Package.
* For the full copyright and license information,
* please view the LICENSE file that was distributed
* with this source code.
*/
namespace SDPHP\EventDispatcherTest\Command;
use Symfony\Component\Config\Loader\DelegatingLoader;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\GenericEvent;
/**
* TimeCommand - Description.
*
* @author Juan Manuel Torres <[email protected]>
*/
class TimeCommand extends Command
{
protected $dispatcher;
public function __construct(EventDispatcher $dispatcher, $name = null)
{
parent::__construct($name);
$this->dispatcher = $dispatcher;
}
protected function configure()
{
$this
->setName('time:show')
->setDescription('Main command to get the current time.')
;
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$event = new GenericEvent();
$this->dispatcher->dispatch('time.before_time', $event); // EVENT BEFORE TIME OBJECT IS CREATED
while (true) {
$dateTime = new \DateTime();
$dateTime->setTimezone(new \DateTimeZone('America/Los_Angeles'));
$this->dispatcher->dispatch('time.after_time', $event); // EVENT AFTER TIME OBJECT IS CREATED
$format = 'g:i:s a';
$this->dispatcher->dispatch('time.before_display', $event); // EVENT BEFORE DISPLAYING THE TIME
$output->writeln($dateTime->format($format));
$sleep = 1;
$this->dispatcher->dispatch('time.after_display', $event); // EVENT AFTER TIME HAS BEEN DISPLAYED.
sleep($sleep);
}
}
}