jalismrs / symfony.common.event
Adds Symfony event listener abstract class
This package's canonical repository appears to be gone and the package has been frozen as a result. Email us for help if needed.
Installs: 431
Dependents: 3
Suggesters: 0
Security: 0
Stars: 0
Watchers: 4
Forks: 0
Open Issues: 0
pkg:composer/jalismrs/symfony.common.event
Requires
- php: ^7.4 || ^8.0
- symfony/console: ^5.0
- symfony/event-dispatcher: ^5.0
Requires (Dev)
- composer/package-versions-deprecated: *
- phpunit/phpunit: 9.4.2
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-05-04 18:17:46 UTC
README
Adds Symfony event listener abstract class
Test
phpunit or vendor/bin/phpunit
coverage reports will be available in var/coverage
Use
ConsoleEventListenerAbstract
use Jalismrs\Symfony\Common\ConsoleEventListenerAbstract; use Symfony\Contracts\EventDispatcher\Event; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Style\SymfonyStyle; use Symfony\Component\EventDispatcher\EventDispatcherInterface; class SomeEvent extends Event { } class SomeConsoleEventListener extends ConsoleEventListenerAbstract { public function onSomeEvent( SomeEvent $someEvent ): SomeEvent { $style = $this->getStyle(); // do something return $someEvent; } } class SomeCommand extends Command { private EventDispatcherInterface $eventDispatcher; private SomeConsoleEventListener $someConsoleEventListener; protected function initialize( InputInterface $input, OutputInterface $output ): void { $style = new SymfonyStyle( $input, $output ); $this->someConsoleEventListener->setStyle($style); } protected function execute( InputInterface $input, OutputInterface $output ): int { $someConsoleEventListenerSomeEvent = [ $this->someConsoleEventListener, 'onSomeEvent', ]; $this->eventDispatcher->addListener( SomeEvent::class, $someConsoleEventListenerSomeEvent, ); $this->eventDispatcher->dispatch( new SomeEvent(), ); $this->eventDispatcher->removeListener( SomeEvent::class, $someConsoleEventListenerSomeEvent, ); return Command::SUCCESS; } }