PHP Classes

Poirot Router: Route requests to callback functions based on URL

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 62 All time: 10,454 This week: 673Up
Version License PHP version Categories
poirot_router 1.0MIT/X Consortium ...5HTTP, PHP 5, Design Patterns
Description 

Author

This package can route requests to callback functions based on URL.

It can take an array of route definitions that specify how requests are handled like URL patterns and parameters.

The package can also check the current URL to determine if one of the configured routes are matched.

Picture of Payam Naderi
  Performance   Level  
Name: Payam Naderi <contact>
Classes: 15 packages by
Country: United States United States
Age: 41
All time rank: 2016286 in United States United States
Week rank: 180 Up22 in United States United States Up
Innovation award
Innovation award
Nominee: 2x

Example

<?php
namespace Poirot\Router
{
    use
Poirot\Router\Interfaces\iRoute;
    use
Poirot\Std\Interfaces\Struct\iData;
    use
Poirot\Std\Type\StdArray;

   
   
/**
     * Merge given params with route defaults
     * @param iRoute $route
     * @param array|\Traversable $params
     */
   
function mergeParamsIntoRouter(iRoute $route, $params)
    {
       
mergeParams($route->params(), $params);
    }

   
/**
     * Merge Params
     *
     * @param iData $params
     * @param array|\Traversable $paramsToMerge
     * @param bool $recursive
     * When parameters exactly given on assemble or something,
     * we don't need merge recursively and instead replace items
     */
   
function mergeParams(iData $params, $paramsToMerge, $recursive = true)
    {
        if (
$paramsToMerge instanceof \Traversable)
           
$paramsToMerge = \Poirot\Std\cast($paramsToMerge)->toArray();

        if (!
is_array($paramsToMerge))
            throw new \
InvalidArgumentException(sprintf(
               
'Parameters must be an array or instance of Traversable; given: (%s).'
               
, \Poirot\Std\flatten($paramsToMerge)
            ));

        if (! empty(
$paramsToMerge) ) {
           
// note: we use route params merge to execute chained action on route match
            // and for this index(priority) of actions in list params in mandatory
            // the first route param first then children param after that
           
if ($recursive) {
               
// Merge Recursive because may have chained Actions.
               
$paramsToMerge = new StdArray($paramsToMerge);
               
$merged = new StdArray( \Poirot\Std\cast($params)->toArray() );

               
$paramsToMerge = $merged->withMergeRecursive($paramsToMerge, false);
            }

           
$params->import($paramsToMerge);
        }
    }
   
    function
encodeUrl($value)
    {
        return
rawurlencode($value);
    }

    function
decodeUrl($value)
    {
        return
rawurldecode($value);
    }
}


Details

Router

Amazing Fast &amp; Flexible Php Router


  Files folder image Files (16)  
File Role Description
Files folder imageInterfaces (2 files, 1 directory)
Files folder imageRoute (5 files)
Files folder imageRouterStack (1 file)
Plain text file aRoute.php Class Class source
Plain text file BuildRouterStack.php Class Class source
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 Data Auxiliary data
Plain text file RouterStack.php Class Class source
Accessible without login Plain text file _functions.php Example Example script

  Files folder image Files (16)  /  Interfaces  
File Role Description
Files folder imageRouterStack (1 file)
  Plain text file iRoute.php Class Class source
  Plain text file iRouterStack.php Class Class source

  Files folder image Files (16)  /  Interfaces  /  RouterStack  
File Role Description
  Plain text file iPreparatorRequest.php Class Class source

  Files folder image Files (16)  /  Route  
File Role Description
  Plain text file RouteHostname.php Class Class source
  Plain text file RouteMethod.php Class Class source
  Plain text file RouteMethodSegment.php Class Class source
  Plain text file RouteSegment.php Class Class source
  Plain text file RouteStackChainWrapper.php Class Class source

  Files folder image Files (16)  /  RouterStack  
File Role Description
  Plain text file StripPrefix.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:62
This week:0
All time:10,454
This week:673Up