wandersonwhcr / phact
该软件包已被废弃,不再维护。没有建议替代包。
使用 Phalcon 框架的简单事件传播
v1.0.0
2014-09-25 18:15 UTC
Requires
- ext-phalcon: *
This package is auto-updated.
Last update: 2021-03-29 00:21:37 UTC
README
Phact 是使用 Phalcon 框架进行简单事件传播的一个示例。使用 Phact,您可以创建一组节点,编写一些事件,并按照一定的顺序执行它们。
示例
use Phact\Manager; use Phact\NodeInterface; use Phalcon\Events\Event; use Phalcon\Events\Manager as EventsManager; class A implements NodeInterface { public function onExecute(Event $event, NodeInterface $node) { if ($node instanceof self) { // or $event->getData() == 'A' echo "A!"; } } } class B implements NodeInterface { public function onBeforeExecute(Event $event, NodeInterface $node) { if ($node instanceof A) { // or $event->getData() == 'A' echo "B before A! "; } } } $manager = (new Manager()) ->setEventsManager(new EventsManager()) ->add('A', new A()) ->add('B', new B()); $manager->execute('A'); // outputs "B before A! A!"
Composer
您可以使用 Composer 在项目中安装 Phact
。
{ "require": { "wandersonwhcr/phact": "1.*" } }
使用方法
您可以使用 NodeInterface
实现三种方法。
use Phact\NodeInterface; use Phalcon\Events\Event; class Node implements NodeInterface { public function onBeforeExecute(Event $event, NodeInterface $node) { } public function onExecute(Event $event, NodeInterface $node) { } public function onAfterExecute(Event $event, NodeInterface $node) { } }
使用这些事件,您可以安排节点执行顺序,创建类似于安装程序或数据库结构更改的出色事件传播。