dms / chainlink-bundle
Wrapper for Chainlink to provide drop in Chain of responsibility implementation into Symfony. Provides tags to inject handlers into configuration defined contexts.
Installs: 5 752
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 6
Forks: 1
Open Issues: 8
Requires
- php: >=5.4
- dms/chainlink: ^0.4
Requires (Dev)
- matthiasnoback/symfony-config-test: ^0.4
- mockery/mockery: ^0.9
- phpunit/phpunit: ~4.5
- scrutinizer/ocular: ~1.1
- symfony/config: ~2.5
- symfony/dependency-injection: ~2.5
- symfony/http-kernel: ~2.5
- dev-master / 1.0.x-dev
- 0.5
- v0.4
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.0
- dev-dependabot/add-v2-config-file
- dev-dependabot/composer/scrutinizer/ocular-1.8.1
- dev-task/gha
- dev-dependabot/composer/symfony/config-2.8.52
- dev-dependabot/composer/symfony/http-kernel-2.8.52
- dev-dependabot/composer/mockery/mockery-0.9.11
- dev-dependabot/composer/matthiasnoback/symfony-config-test-2.2.0
- dev-dependabot/composer/phpunit/phpunit-4.8.28
- dev-dependabot/composer/symfony/dependency-injection-2.8.50
This package is auto-updated.
Last update: 2024-10-29 04:36:45 UTC
README
This Bundle wraps Chainlink library and offers a drop in solution to implement the Chain of Responsibility pattern, based on Symfony service tags. It allows you to, via configuration, setup multiple contexts and define which tags provide handlers for each.
Installation
To get the Bundle code, run:
composer require dms/chainlink-bundle
Edit your AppKernel.php
file to instantiate the Bundle:
<?php // app/AppKernel.php public function registerBundles() { $bundles = array( // ... new DMS\Chainlink\Bundle\DMSChainlinkBundle(), ); }
If you are looking for other frameworks, check Packagist for wrappers and adapters.
Usage
To register new Contexts and assign handlers to them, simply add configuration entries in your config.yml
.
dms_chainlink: contexts: my_new_context: tag: mycontext.handler
The bundle will look for any services tagged with the tag
defined above and inject them as handlers in the context you requested.
To handle a request, retrieve the Context from the Container and pass in your input.
$this->container->get('dms_chainlink.context.my_new_context')->handle($input); //or its also aliased at $this->container->get('my_new_context')->handle($input);
Services that will be used as handlers need to implement the HandlerInterface
from Chainlink. Its the handler's responsibility to identify which input it is responsible for, the interface contains a handles
method that is called for that.
Order of Chain handling
As of version 0.3, Chainlink supports ordering of the handlers using the priority system used extensively in Symfony. The handlers will be called from high to low.
# src/Vendor/MyBundle/Resources/config/services.yml my_service: class: MyHandler tag: - { name: my_new_context, priority: 1 } my_other_service: class: OtherHandler tag: - { name: my_new_context, priority: 9001 }
In this case OtherHandler
will be called first, and then MyHandler
, provided they can handle the usecase.