2017 © Pedro Peláez
 

library slim-routing-manager

An approximation to the Symfony's routing system in SlimFramework

image

jlaso/slim-routing-manager

An approximation to the Symfony's routing system in SlimFramework

  • Monday, August 18, 2014
  • by jlaso
  • Repository
  • 1 Watchers
  • 3 Stars
  • 32 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 2 Versions
  • 3 % Grown

The README.md

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

This is an improvement to SlimFramework that permits to declare routes with the style of Symfony2, (*2)

If you want to see a real demo you can clone this repository and launch composer install, (*3)

or to visit this post to see a complete demo in action, (*4)

The idea is to have this structure in the front controller (normally index.php), (*5)

new RoutingCacheManager(  
  array(  
    'cache'      => __DIR__ . '/cache/routing',  
    'controller' => __DIR__ . '/app/controller',  
  )  
);  

The default values of cache and controller are exactly the shown, i.e. the previous sentence is equivalen to:, (*6)

new RoutingCacheManager();  

And the 'controller' key accept a path or an array of paths, for instance:, (*7)

new RoutingCacheManager(
   array(
      'cache'      => __DIR__ . '/cache/routing',
      'controller' => array(
         __DIR__ . '/app/controller',
         __DIR__ . '/app/subcontroller',
        )
    )
);

Obviouslly the 'cache' path must to be write rights for the http/apache daemon user., (*8)

The idea is that RoutingCacheManager process the xxxxController classes that exist in the path/paths and creates for each one a Slim loader version., (*9)

Let see an example., (*10)

This is the content of app/controller/FrontendController.php, (*11)

    class FrontendController extends Controller
    {
      /**
       * @Route('/')
       * @Name('home.index')
       */
       public function sampleRouteAction()
       {
            /** @var Slim\Slim $slim */
            $slim = $this->getSlim();
            $slim->response()->body('This is the home route ' . $this->getName());
       }
    }

As you can see the annotations are very clear and reflect clearly the intention of this route endopoint, (*12)

The problem is that Slim doesn't understand this structure and we need to pass to this format:, (*13)

$app->map("/", function(){ blah blah blah })->via("GET")->name("home.index");

Then our SlimRoutingManager process the FrontendController class and creates a little loader with the Slim flavour:, (*14)

$app->map("/", "FrontendController::___sampleRouteAction")->via("GET")->name("home.index");

The main Controller class does the magic changing the invocation of this pseudo static method __sampleRouteAction to the correct method., (*15)

The Versions

18/08 2014

dev-master

9999999-dev http://github.com/jlaso/slim-routing-manager

An approximation to the Symfony's routing system in SlimFramework

  Sources   Download

MIT

The Requires

 

router slimframework

16/08 2014

1.0

1.0.0.0 http://github.com/jlaso/slim-routing-manager

An approximation to the Symfony's routing system in SlimFramework

  Sources   Download

MIT

The Requires

 

router slimframework