PHP code example of nathanburkett / event-dispatcher
1. Go to this page and download the library: Download nathanburkett/event-dispatcher library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// ContainerReflectionResolver will instantiate an EventListener by resolving any dependencies from a ContainerInterface
$resolver = new ContainerReflectionResolver($container);
// DescendingSubscriptionComparator ensures proper ordering of Subscriptions inside a SortingAlgorithm
$comparator = new DescendingSubscriptionComparator();
$sorter = new SortingAlgorithm($comparator);
$provider = new ListenerProvider($resolver, $sorter);
// SendValidateEmailMail could have a Mailer already existing in the container as a dependency in
// its constructor
$sendValidateEmail = new Subscription(NewUserRegistered::class, SendValidateEmailMail::class);
// CompleteNewUserProfile could have a ProfileRepository already existing in the container as a
// dependency in its constructor
$completeUserProfile = new Subscription(NewUserRegistered::class, CompleteNewUserProfile::class);
$provider->addSubscription($sendValidateEmail);
$provider->addSubscription($completeUserProfile);
$dispatcher = new EventDispatcher();
// or resolve an EventDispatcher singleton from container
// $dispatcher = $this->container->get(EventDispatcherInterface::class);
$dispatcher->addListenerProvider($provider);
$emitter = new EventEmitter($dispatcher);
// ...
$user = new User('Nathan Burkett', '[email protected]');
$event = new NewUserRegistered($user);
$emitter->emit($event);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.