2017 © Pedro Peláez
 

library route

Two-step controller routing for League/route. Instantiate your controller, do some stuff, then call your controller method.

image

laasti/route

Two-step controller routing for League/route. Instantiate your controller, do some stuff, then call your controller method.

  • Thursday, April 14, 2016
  • by nebulousGirl
  • Repository
  • 1 Watchers
  • 0 Stars
  • 172 Installations
  • PHP
  • 1 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 1 % Grown

The README.md

Laasti/Route

An advanced implementation of PHP League Route package. A two-step route middleware for Laasti/Stack., (*1)

Instead of mapping directly to your controller, a middle step is added: a route object is used to configure the current route. This middle step can be used to check user's rights to access a route through an Authorization middleware., (*2)

Uses the excellent package from The PHP League: League/Route., (*3)

Installation

composer require laasti/route

Usage

Currently does not support closures nor functions as routes, only objects., (*4)

With Laasti\Stack:, (*5)

   $container = new League\Container;
   $routes = new League\Route\RouteCollection($container);
   $container->add('Laasti\Route\DefineControllerMiddleware')->withArgument($routes);
   $routes->setStrategy(new Laasti\Route\ControllerDefinitionStrategy);
   $request = Symfony\Component\HttpFoundation\Request::create('/test');
   $routes->get('/test', 'MyController::display');
   $resolver = new Laasti\Stack\ContainerResolver($container);
   $stack = new Laasti\Stack\Stack($resolver);
   $stack->push('Laasti\Route\DefineControllerMiddleware');
   $stack->push('Laasti\Route\CallControllerMiddleware');

   $stack->execute($request);

Without Laasti\Stack:, (*6)

   $container = new League\Container;
   $routes = new League\Route\RouteCollection($container);
   $routes->setStrategy(new Laasti\Route\ControllerDefinitionStrategy);
   $request = Symfony\Component\HttpFoundation\Request::create('/test/George');
   $routes->get('/test/{name}', 'MyController::display');

   $definition = $routes->getDispatcher()->dispatch($request->getMethod(), $request->getPathInfo());

   //Pass the request or any arguments to the controller
   //Calls MyController->display($request);
   $request->attributes->add($definition->getArguments());
   echo $definition->callController($request);

   //Or, uses route attributes as arguments
   //Calls MyController->display($name);
   echo $definition->callController();

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

History

See CHANGELOG.md for more information., (*7)

Credits

Author: Sonia Marquette (@nebulousGirl), (*8)

License

Released under the MIT License. See LICENSE.txt file., (*9)

The Versions

14/04 2016

dev-master

9999999-dev

Two-step controller routing for League/route. Instantiate your controller, do some stuff, then call your controller method.

  Sources   Download

MIT

The Requires

 

The Development Requires

14/04 2016

v1.1.1

1.1.1.0

Two-step controller routing for League/route. Instantiate your controller, do some stuff, then call your controller method.

  Sources   Download

MIT

The Requires

 

The Development Requires

30/09 2015

v1.1

1.1.0.0

Two-step controller routing for League/route. Instantiate your controller, do some stuff, then call your controller method.

  Sources   Download

MIT

The Requires

 

The Development Requires

24/08 2015

v1.0

1.0.0.0

Two-step controller routing for League/route. Instantiate your controller, do some stuff, then call your controller method.

  Sources   Download

MIT

The Requires

 

The Development Requires

23/08 2015

dev-develop

dev-develop

A route middleware for Laasti/Stack.

  Sources   Download

MIT

The Requires

 

The Development Requires