Event事件

自定义事件

  • 事件对象Event,自定义Event {#事件对象event与如何定义一个event,例如:}
  1. <?php
  2. namespace Group\Events;
  3. class Event
  4. {
  5. protected $property;
  6. public function __construct($property = null)
  7. {
  8. $this->property = $property;
  9. }
  10. public function getProperty()
  11. {
  12. return $this->property;
  13. }
  14. public function setProperty($property)
  15. {
  16. $this->property = $property;
  17. }
  18. }
  • 自定义Event {#事件对象event与如何定义一个event,例如:}
  1. <?php
  2. namespace Group\Events;
  3. final class QueueEvent extends \Event
  4. {
  5. const CRASH = "server.crash";
  6. protected $server;
  7. protected $host;
  8. public function __construct($server, $host)
  9. {
  10. $this->server = $server;
  11. $this->host = $host;
  12. }
  13. public function getServer()
  14. {
  15. return $this->server;
  16. }
  17. public function getHost()
  18. {
  19. return $this->host;
  20. }
  21. }

框架内部事件

  • kernal.init {#kernalinit}
  • kernal.response {#kernalresponse}
  • kernal.request {#kernalrequest}
  • kernal.exception {#kernalexception}
  • kernal.notfound {#kernalnotfound}
  • kernal.httpfinish {#kernalhttpfinish}
  • kernal.service_call {#kernalhttpfinish}
  • kernal.service_fail {#kernalhttpfinish}

预先需要绑定的监听事件,可以编辑config/listener.php,添加预绑定事件的监听器

如何派发事件Event见EventDispatcher事件调度