2017 © Pedro Peláez
 

library silex-controller-service

Controller service provider for Silex2.

image

meta-tech/silex-controller-service

Controller service provider for Silex2.

  • Thursday, March 30, 2017
  • by Meta-Tech
  • Repository
  • 1 Watchers
  • 0 Stars
  • 49 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

MetaTech Silex ControllerServiceProvider

A service provider for Silex for managing DI and mounting on controllers., (*1)

Requirements

PHP 7.0, (*2)

Install

The package can be installed using Composer ., (*3)

composer require meta-tech/silex-controller-service

Or add the package to your composer.json., (*4)

"require": {
    "meta-tech/silex-controller-service" : "~1.0"
}

Usage

The provider will create a service relative to a Controller instance builded with its dependencies.
If the controller implements the Silex\Api\ControllerProviderInterface the provider will also mount the controller 's routes to the defined routing entry point, (*5)

Example

Admit you have a controller Test with dependencies on instanciation :, (*6)

class Test implements ControllerProviderInterface
{
    public function __construct(Application $app, string $foo)
    {
        // do stuff
    }

You can use the ControllerServiceProvider to create a service to manage your controller class instanciation :, (*7)


use MetaTech\Silex\Provider\ControllerServiceProvider; use Acme\Ctrl\Test; ... $app->register(new ControllerServiceProvider(Test::class, [$app, 'foo'], '/test', 'ctrl.'));

first parameter is your controller class
second parameter is an array of your controller dependencies (default [])
third parameter define your controller routing entry point (default null : disabling mounting controller's routes)
fourth parameter define your service 's namespace to access your controller (default 'ctrl.'), (*8)

The name of the registering service is the given namespace followed by your controller class shortname, (*9)

With the previous example $app['ctrl.Test'] is now available and return your controller instance., (*10)

the connect method of your controller can now benefits of this service to define appropriate routes, like that :, (*11)

class Test implements ControllerProviderInterface
{
    ...

    public function connect(Application $app)
    {
        $collection = $app['controllers_factory'];
        $_          = 'ctrl.Test';

        $collection->match('/'    , "$_:index");
        $collection->match('/test', "$_:test");

        return $collection;
    }
}

Controller 's routes are mount on the defined routing entry point (third parameter);, (*12)

see source code of MetaTech\Silex\Ws\Controller in meta-tech\silex-core for an advance controller architecture., (*13)

License

The project is released under the MIT license, see the LICENSE file., (*14)

The Versions

30/03 2017

dev-master

9999999-dev https://github.com/meta-tech/silex-controller-service

Controller service provider for Silex2.

  Sources   Download

MIT

The Requires

 

service silex controller provider

15/03 2017

1.0.0

1.0.0.0 https://github.com/meta-tech/silex-controller-service

Controller service provider for Silex2.

  Sources   Download

MIT

The Requires

 

service silex controller provider