2017 © Pedro Peláez
 

library dispatcher-controller

Psr-15 middleware dispatcher factory resolving controller definitions

image

ellipse/dispatcher-controller

Psr-15 middleware dispatcher factory resolving controller definitions

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

The README.md

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

Require php >= 7.0, (*2)

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

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

Create a dispatcher factory resolving controller definitions

This package provides an Ellipse\Dispatcher\ControllerResolver 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 controller definitions as Ellipse\Handlers\ControllerRequestHandler instances from the ellipse/handlers-controller package., (*7)

<?php

namespace App;

use SomePsr11Container;

use Ellipse\DispatcherFactory;
use Ellipse\Dispatcher\ControllerResolver;

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

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

Controller definitions

An instance of ControllerRequestHandler needs the container entry id of an object used as controller, a method name and an optional array of request attribute names. A controller definition defines which controller class, method name and request attributes should be used by the ControllerRequestHandler. It is an array with at least two string elements:, (*8)

  • The first one is the controller fully qualified class name
  • The second one is the name of the controller method to execute prepended with '@'
  • The optional third element is an array of strings representing names of the request attributes to use as parameters when calling the controller method

For example [SomeController::class, '@index'] and [SomeController::class, '@show', ['some_id']] are valid controller definitions. The first one execute the SomeController class ->index() method and the second one execute its ->show($id) method using the value of the request attribute named 'some_id' as parameter., (*9)

This array notation was prefered over a string like 'SomeController@index' so there is no need to deal with controller namespaces. Also the method name start with a '@' because [SomeController::class, 'index'] is considered as a callable by php, even when the index method is not static!, (*10)

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

<?php

namespace App;

use SomePsr11Container;

use Ellipse\DispatcherFactory;
use Ellipse\Dispatcher\ControllerResolver;

use App\Controllers\SomeController;

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

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

// Dispatchers using controller definitions as Psr-15 request handler can now be created.
$dispatcher1 = $factory([SomeController::class, '@index'], [new SomeMiddleware]);
$dispatcher2 = $factory([SomeController::class, '@show', ['some_id']], [new SomeMiddleware]);
$dispatcher3 = $factory([SomeController::class, '@store'], [new SomeMiddleware]);

The Versions

23/03 2018

dev-master

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

Psr-15 middleware dispatcher factory resolving controller definitions

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

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

23/03 2018
13/03 2018

1.1.1

1.1.1.0 https://github.com/ellipsephp/dispatcher-controller

Psr-15 middleware dispatcher factory resolving controller definitions from Psr-11 container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

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

04/03 2018

1.1.0

1.1.0.0 https://github.com/ellipsephp/dispatcher-controller

Psr-15 middleware dispatcher factory resolving controller definitions from Psr-11 container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

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

22/02 2018

1.0.7

1.0.7.0 https://github.com/ellipsephp/dispatcher-controller

Psr-15 middleware dispatcher factory resolving controller definitions from Psr-11 container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

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

30/01 2018

1.0.6

1.0.6.0 https://github.com/ellipsephp/dispatcher-controller

Psr-15 middleware dispatcher factory resolving controller definitions from Psr-11 container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

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

28/01 2018

1.0.5

1.0.5.0 https://github.com/ellipsephp/dispatcher-controller

Psr-15 middleware dispatcher factory resolving controller definitions from Psr-11 container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

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

23/01 2018

1.0.4

1.0.4.0 https://github.com/ellipsephp/dispatcher-controller

Psr-15 middleware dispatcher factory resolving controller definitions from Psr-11 container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

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

14/01 2018

1.0.3

1.0.3.0 https://github.com/ellipsephp/dispatcher-controller

Psr-15 middleware dispatcher factory resolving controller definitions from Psr-11 container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

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

12/01 2018

1.0.2

1.0.2.0 https://github.com/ellipsephp/dispatcher-controller

Psr-15 middleware dispatcher factory resolving controller definitions from Psr-11 container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

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

09/01 2018

1.0.1

1.0.1.0 https://github.com/ellipsephp/dispatcher-controller

Psr-15 middleware dispatcher factory resolving controller definitions from Psr-11 container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

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

07/01 2018

1.0.0

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

Psr-15 middleware dispatcher factory resolving controller definitions from Psr-11 container

  Sources   Download

MIT

The Requires

 

The Development Requires

by Pierre Mallinjoud

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