orbiter/satellite

PHP Event Dispatcher with listener and PSR-14 dispatcher, compatible with PSR-11 container and custom invokers.

0.4.0 2022-10-19 19:25 UTC

This package is auto-updated.

Last update: 2024-10-19 23:53:46 UTC


README

Latest Stable Version Latest Unstable Version codecov Total Downloads Github actions Build PHP Version Require

  • PSR-14 Event Dispatcher and Listener
  • using InvokerInterface to execute anything, PSR-11 compatible

Check satellite-app for a ready to use template, or install just this event library:

composer require orbiter/satellite

Dependencies, using PHP-DI here, but possible with any PSR-11 container and any implementation of InvokerInterface:

use function DI\autowire;
use function DI\get;

$dependencies = [
    Satellite\Event\EventListenerInterface::class => autowire(Satellite\Event\EventListener::class),
    Psr\EventDispatcher\ListenerProviderInterface::class => get(Satellite\Event\EventListenerInterface::class),
    Satellite\Event\EventDispatcher::class => autowire()
        ->constructorParameter('listener', get(Psr\EventDispatcher\ListenerProviderInterface::class))
        ->constructorParameter('invoker', get(Invoker\InvokerInterface::class)),
    Psr\EventDispatcher\EventDispatcherInterface::class => get(Satellite\Event\EventDispatcher::class),
];

For full invocation PSR-11 injection based on Reflection, set up the Invoker with the included InvokerTypeHintContainerResolver:

/**
 * @var $invoker \Invoker\Invoker
 */
$invoker = $container->get(\Invoker\Invoker::class);
$invoker->getParameterResolver()->prependResolver(
    new Satellite\InvokerTypeHintContainerResolver($container)
);

Dev Notices

Commands to set up and run e.g. tests:

# on windows:
docker run -it --rm -v %cd%:/app composer install

docker run -it --rm -v %cd%:/var/www/html php:8.1-cli-alpine sh

docker run --rm -v %cd%:/var/www/html php:8.1-cli-alpine sh -c "cd /var/www/html && ./vendor/bin/phpunit --testdox -c phpunit-ci.xml --bootstrap vendor/autoload.php"

# on unix:
docker run -it --rm -v `pwd`:/app composer install

docker run -it --rm -v `pwd`:/var/www/html php:8.1-cli-alpine sh

docker run --rm -v `pwd`:/var/www/html php:8.1-cli-alpine sh -c "cd /var/www/html && ./vendor/bin/phpunit --testdox -c phpunit-ci.xml --bootstrap vendor/autoload.php"

Versions

This project adheres to semver, until 1.0.0 and beginning with 0.1.0: all 0.x.0 releases are like MAJOR releases and all 0.0.x like MINOR or PATCH, modules below 0.1.0 should be considered experimental.

License

This project is free software distributed under the MIT LICENSE.

Contributors

By committing your code to the code repository you agree to release the code under the MIT License attached to the repository.

Maintained by Michael Becker