Skip to content

Commit 6d91b50

Browse files
committed
First commit.
0 parents  commit 6d91b50

File tree

5 files changed

+245
-0
lines changed

5 files changed

+245
-0
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
vendor/*
2+
.DS_Store

Diff for: composer.json

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "sdphp/event-dispatcher-test",
3+
"homepage": "http://sdphp.org",
4+
"keywords":["console", "CLI", "event-dispatcher"],
5+
"license":"MIT",
6+
"authors": [
7+
{
8+
"name": "Juan Manuel Torres.",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"require": {
13+
"php": ">=5.4",
14+
"symfony/console": "~2.6",
15+
"symfony/event-dispatcher": "~2.6"
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"SDPHP\\EventDispatcherTest\\": "src"
20+
}
21+
},
22+
"extra": {
23+
"branch-alias": {
24+
"dev-master": "1.0.x-dev"
25+
}
26+
}
27+
}
28+

Diff for: composer.lock

+135
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: console

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env php
2+
<?php
3+
set_time_limit(0);
4+
require_once __DIR__.'/vendor/autoload.php';
5+
6+
use SDPHP\EventDispatcherTest\Command\TimeCommand;
7+
use Symfony\Component\Console\Application;
8+
use Symfony\Component\EventDispatcher\EventDispatcher;
9+
10+
$dispatcher = new EventDispatcher();
11+
12+
$application = new Application();
13+
$application->add(new TimeCommand($dispatcher));
14+
$application->run();

Diff for: src/Command/TimeCommand.php

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

0 commit comments

Comments
 (0)