PHP Classes

Slim Routing Manager: Read routes from controller class annotations

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-09 (10 months ago) RSS 2.0 feedNot enough user ratingsTotal: 333 All time: 7,123 This week: 86Up
Version License PHP version Categories
slim-routing-manager 1.0.10MIT/X Consortium ...5.3.7PHP 5, Libraries, Design Patterns
Description 

Author

This package can read routes from controller class annotations.

It allows declaring routes for Slim framework applications by parsing annotations defined in controller classes.

The path of the controller classes to be parsed and the route cache information path are configurable parameters.

Picture of Joseluis Laso
  Performance   Level  
Name: Joseluis Laso <contact>
Classes: 16 packages by
Country: Spain Spain
Age: 56
All time rank: 92119 in Spain Spain
Week rank: 62 Up2 in Spain Spain Up
Innovation award
Innovation award
Nominee: 6x

Winner: 2x

Documentation

Latest Stable Version Total Downloads Latest Unstable Version License

This is an improvement to SlimFramework that permits to declare routes with the style of Symfony2

If you want to see a real demo you can clone this repository and launch composer install

or to visit this post to see a complete demo in action

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

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:

new RoutingCacheManager();  

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

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.

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

Let see an example.

This is the content of app/controller/FrontendController.php

    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

The problem is that Slim doesn't understand this structure and we need to pass to this format:

$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:

$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.


  Files folder image Files (5)  
File Role Description
Files folder imageJLaso (1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (5)  /  JLaso  
File Role Description
Files folder imageSlimRoutingManager (1 file, 1 directory)

  Files folder image Files (5)  /  JLaso  /  SlimRoutingManager  
File Role Description
Files folder imageController (1 file)
  Accessible without login Plain text file RoutingCacheManager.php Class Class source

  Files folder image Files (5)  /  JLaso  /  SlimRoutingManager  /  Controller  
File Role Description
  Accessible without login Plain text file Controller.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:333
This week:0
All time:7,123
This week:86Up