Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/deprecated-packages/symfonyeventdispatcher
[DEPRECATED] Use this instead →
https://github.com/deprecated-packages/symfonyeventdispatcher
event-dispatcher events nette php71 symfony symplify
Last synced: 22 days ago
JSON representation
[DEPRECATED] Use this instead →
- Host: GitHub
- URL: https://github.com/deprecated-packages/symfonyeventdispatcher
- Owner: deprecated-packages
- License: mit
- Created: 2016-12-18T13:17:40.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-05-05T11:22:26.000Z (over 7 years ago)
- Last Synced: 2024-10-15T01:21:45.950Z (22 days ago)
- Topics: event-dispatcher, events, nette, php71, symfony, symplify
- Language: PHP
- Homepage: https://github.com/contributte/event-dispatcher
- Size: 85 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# The Simplest [Symfony Event Dispatcher](http://symfony.com/doc/current/components/event_dispatcher.html) integration to Nette
[![Build Status](https://img.shields.io/travis/Symplify/SymfonyEventDispatcher/master.svg?style=flat-square)](https://travis-ci.org/Symplify/SymfonyEventDispatcher)
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Symplify/SymfonyEventDispatcher.svg?style=flat-square)](https://scrutinizer-ci.com/g/Symplify/SymfonyEventDispatcher)
[![Downloads](https://img.shields.io/packagist/dt/symplify/symfony-event-dispatcher.svg?style=flat-square)](https://packagist.org/packages/symplify/symfony-event-dispatcher)## Install
```sh
composer require symplify/symfony-event-dispatcher
```Register the extension in `config.neon`:
```yaml
# app/config/config.neonextensions:
- Symplify\SymfonyEventDispatcher\Adapter\Nette\DI\SymfonyEventDispatcherExtension
```## Usage
See [short article about EventDispatcher](http://pehapkari.cz/blog/2016/12/05/symfony-event-dispatcher).
**This article is tested** – it will be still up-to-date with Symfony 4+.### 1. Create class that implements `Symfony\Component\EventDispatcher\SubscriberInterface`:
```php
// app/EventSubscriber/CheckRequestEventSubscriber.phpnamespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\GetResponseEventfinal class CheckRequestEventSubscriber implements EventSubscriberInterface
{
/**
* @var bool
*/
public $isUserNotified = false;public static function getSubscribedEvents(): array
{
// in format ['event name' => 'public function name that will be called']
return [KernelEvents::REQUEST => 'validateRequest'];
}// Appropriate event object is passed in arguments
public function validateRequest(GetResponseEvent $event): void
{
// some logic to send notification
$this->isUserNotified = true;
}
}
```### 2. Register it to services
```yaml
# app/config/config.neonservices:
- App\EventSubscriber\CheckRequestEventSubscriber
```And it works :)
That's all!
## Contributing
Send [issue](https://github.com/Symplify/Symplify/issues) or [pull-request](https://github.com/Symplify/Symplify/pulls) to main repository.