Giter VIP home page Giter VIP logo

dispatcher-adr's Introduction

ADR resolver

This package provides a factory decorator for objects implementing Ellipse\DispatcherFactoryInterface from ellipse/dispatcher package. It allows to produce instances of Ellipse\Dispatcher using ADR definitions.

Require php >= 7.0

Installation composer require ellipse/dispatcher-adr

Run tests ./vendor/bin/kahlan

Create a dispatcher factory resolving ADR definitions

This package provides an Ellipse\Dispatcher\ActionResolver class implementing Ellipse\DispatcherFactoryInterface which allows to decorate any other object implementing this interface.

It takes a container implementing Psr\Container\ContainerInterface as first parameter and the factory to decorate as second parameter.

Once decorated, the resulting dispatcher factory can be used to produce instances of Ellipse\Dispatcher by resolving ADR definitions as Ellipse\Handlers\ActionRequestHandler instances from the ellipse/handlers-adr package.

<?php

namespace App;

use SomePsr11Container;

use Ellipse\DispatcherFactory;
use Ellipse\Dispatcher\ActionResolver;

// Get some Psr-11 container.
$container = new SomePsr11Container;

// Decorate a DispatcherFactoryInterface implementation with an ActionResolver.
$factory = new ActionResolver($container, new DispatcherFactory);

ADR definitions

An instance of ActionRequestHandler needs a container entry id of an object implementing Ellipse\ADR\DomainInterface, a container entry id of an object implementing Ellipse\Handlers\ResponderInterface and an optional array of default input. An ADR definition defines which Domain class, Responder class and default input should be used by the ActionRequestHandler. It can take two forms:

  • A string representing the fully qualified name of a Domain class
  • An array with at least one string as first element representing the fully qualified name of a Domain class. The fully qualified name of a Responder class and a default input array can be specified as optional second and third elements

For example SomeDomain::class, [SomeDomain::class], [SomeDomain::class, SomeResponder::class] and [SomeDomain::class, SomeResponder::class, ['default' => 'value']] are valid ADR definitions, assuming SomeDomain class implements DomainInterface and SomeResponder implements ResponderInterface.

When no Responder class name is specified (SomeDomain::class and [SomeDomain::class]), the container entry id used to retrieve the Responder instance defaults to Ellipse\Handlers\ResponderInterface. It allows to use a default Responder class when none is defined.

ActionRequestHandler logic is described on the ellipse/handlers-adr documentation page.

<?php

namespace App;

use SomePsr11Container;

use Ellipse\DispatcherFactory;
use Ellipse\Dispatcher\ActionResolver;

// Get some Psr-11 container.
$container = new SomePsr11Container;

// Decorate a DispatcherFactoryInterface implementation with an ActionResolver.
$factory = new ActionResolver($container, new DispatcherFactory);

// Dispatchers using ADR definitions as Psr-15 request handler can now be created.
$dispatcher1 = $factory(SomeDomain::class, [new SomeMiddleware]);
$dispatcher2 = $factory([SomeDomain::class], [new SomeMiddleware]);
$dispatcher3 = $factory([SomeDomain::class, SomeResponder::class], [new SomeMiddleware]);
$dispatcher4 = $factory([SomeDomain::class, SomeResponder::class, ['default' => 'value']], [new SomeMiddleware]);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.