项目作者: robinvdvleuten

项目描述 :
😴 An event dispatcher that holds any events until flushed.
高级语言: PHP
项目地址: git://github.com/robinvdvleuten/php-lazy-event-dispatcher.git
创建时间: 2017-03-27T19:33:57Z
项目社区:https://github.com/robinvdvleuten/php-lazy-event-dispatcher

开源协议:MIT License

下载


LazyEventDispatcher

An event dispatcher that holds any events until flushed.

Latest Stable Version
Build Status

Use Case

If you want to make use of the kernel.terminate event to do some
“heavy” action after the response has already streamed back to the client. Symfony does this already by default but with this
listener you’ll have support for any custom event classes.

Installation

The recommended way to install the library is through Composer.

  1. composer require robinvdvleuten/lazy-event-dispatcher

Install the listener as a service afterwards;

  1. services:
  2. app.lazy_event_dispatcher:
  3. class: Rvdv\LazyEventDispatcher\LazyEventDispatcher
  4. arguments:
  5. - "@event_dispatcher"
  6. tags:
  7. - { name: kernel.event_listener, event: kernel.terminate, method: flush }

Then add a custom compiler pass to have a new event listener type;

  1. <?php
  2. namespace AppBundle;
  3. use Symfony\Component\DependencyInjection\Compiler\PassConfig;
  4. use Symfony\Component\DependencyInjection\ContainerBuilder;
  5. use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
  6. use Symfony\Component\HttpKernel\Bundle\Bundle;
  7. class AppBundle extends Bundle
  8. {
  9. /**
  10. * {@inheritdoc}
  11. */
  12. public function build(ContainerBuilder $container)
  13. {
  14. $container->addCompilerPass(
  15. new RegisterListenersPass('app.lazy_event_dispatcher', 'lazy.event_listener', 'lazy.event_subscriber'),
  16. PassConfig::TYPE_BEFORE_REMOVING
  17. );
  18. }
  19. }

You’ll then can register any “lazy” event listeners like this;

  1. services:
  2. app.custom_event_listener:
  3. class: AppBundle\EventListener\CustomEventListener
  4. tags:
  5. - { name: lazy.event_listener, event: custom_event }

License

MIT © Robin van der Vleuten