2017 © Pedro Peláez
 

library dispatcher-adr

Psr-15 middleware dispatcher factory resolving ADR definitions

image

ellipse/dispatcher-adr

Psr-15 middleware dispatcher factory resolving ADR definitions

  • Friday, March 23, 2018
  • by pmall
  • Repository
  • 1 Watchers
  • 0 Stars
  • 1 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

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., (*1)

Require php >= 7.0, (*2)

Installation composer require ellipse/dispatcher-adr, (*3)

Run tests ./vendor/bin/kahlan, (*4)

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., (*5)

It takes a container implementing Psr\Container\ContainerInterface as first parameter and the factory to decorate as second parameter., (*6)

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., (*7)

<?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:, (*8)

  • 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., (*9)

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., (*10)

ActionRequestHandler logic is described on the ellipse/handlers-adr documentation page., (*11)

<?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]);

The Versions

23/03 2018

dev-master

9999999-dev https://github.com/ellipsephp/dispatcher-adr

Psr-15 middleware dispatcher factory resolving ADR definitions

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

middleware container dispatcher adr psr-11 psr-15 request-handler

23/03 2018

1.0.0

1.0.0.0 https://github.com/ellipsephp/dispatcher-adr

Psr-15 middleware dispatcher factory resolving ADR definitions

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

middleware container dispatcher adr psr-11 psr-15 request-handler