-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from inhere/dev
Dev
- Loading branch information
Showing
21 changed files
with
876 additions
and
520 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: Inhere | ||
* Date: 2017/12/14 0014 | ||
* Time: 22:25 | ||
*/ | ||
|
||
namespace Inhere\Event\Examples; | ||
|
||
|
||
use Inhere\Event\EventInterface; | ||
use Inhere\Event\EventSubscriberInterface; | ||
use Inhere\Event\ListenerPriority; | ||
|
||
/** | ||
* Class EnumGroupListener | ||
* @package Inhere\Event\Examples | ||
*/ | ||
class EnumGroupListener implements EventSubscriberInterface | ||
{ | ||
const TEST_EVENT = 'test'; | ||
const POST_EVENT = 'post'; | ||
|
||
/** | ||
* 配置事件与对应的处理方法 | ||
* @return array | ||
*/ | ||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
self::TEST_EVENT => 'onTest', | ||
self::POST_EVENT => ['onPost', ListenerPriority::LOW], | ||
]; | ||
} | ||
|
||
public function onTest(EventInterface $event) | ||
{ | ||
$pos = __METHOD__; | ||
echo "handle the event {$event->getName()} on the: $pos\n"; | ||
} | ||
|
||
public function onPost(EventInterface $event) | ||
{ | ||
$pos = __METHOD__; | ||
echo "handle the event {$event->getName()} on the: $pos\n"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: inhere | ||
* Date: 2017-12-07 | ||
* Time: 14:07 | ||
*/ | ||
|
||
use Inhere\Event\EventManager; | ||
use Inhere\Event\Examples\EnumGroupListener; | ||
|
||
require dirname(__DIR__) . '/tests/boot.php'; | ||
|
||
$em = new EventManager(); | ||
|
||
// register a group listener | ||
$em->addListener(new EnumGroupListener()); | ||
|
||
$demo = new class | ||
{ | ||
use \Inhere\Event\EventManagerAwareTrait; | ||
|
||
public function run() | ||
{ | ||
$this->eventManager->trigger(EnumGroupListener::TEST_EVENT); | ||
|
||
echo '.'; | ||
sleep(1); | ||
echo ".\n"; | ||
|
||
$this->eventManager->trigger(EnumGroupListener::POST_EVENT); | ||
} | ||
}; | ||
|
||
$demo->setEventManager($em); | ||
$demo->run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.