2017 © Pedro Peláez
 

library routing-manager

PHP performance-oriented routing manager

image

marco476/routing-manager

PHP performance-oriented routing manager

  • Tuesday, June 13, 2017
  • by marco476
  • Repository
  • 1 Watchers
  • 2 Stars
  • 25 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 16 Versions
  • 0 % Grown

The README.md

Build Status Packagist Code Climate Issue Count PHP Version Packagist, (*1)

PHP performance-oriented Routing manager

This library is PHP performance-oriented routing manager working with routes setted by:, (*2)

  • PHP Array
  • YAML file
  • XML file

Installation

You can install it with Composer:, (*3)

composer require marco476/routing-manager

Usage

Use the routing-manager library is extreme simple. All routes setted must include an expression key/tag for matching with URI., (*4)

When you call matchRoute method, the library find a match between routes setted and URI present. It return the route matched array if math with URI is Ok or false if not., (*5)

Array

See an example with array:, (*6)

setRoutes(array(
    'homepage' => array( //Name route
        'expression'     => '/', //MUST DEFINE!
        'controller'=> 'MyController',
        'action'    => 'MyAction',
        'extra1'    => 'extra1',
        'extra2'    => 'extra2'
    )
));

if ($routeMatch = $Routing->matchRoute()) {
    echo "See that" . "
"; var_dump($routeMatch); } else { echo "mmm.. what's wrong?"; } ``` ### YML See an example with **YML**: ```PHP setRoutesFromYml(__DIR__, 'routes.yml'); if ($routeMatch = $Routing->matchRoute()) { echo "See that" . "
"; var_dump($routeMatch); } else { echo "mmm.. what's wrong?"; } ``` And see a YML routes configuration file: ```YML homepage: #Name route expression: "/" #MUST DEFINE! controller: "MyController" action: "MyAction" params: ["myFirstParameter", "sendMe"] ``` > Note: If you want use a YAML file routes configuration, you must install the yaml php extension. You can install it with *sudo apt-get install php-yaml* or with *PECL*. For detail, [see that](http://bd808.com/pecl-file_formats-yaml/) ### XML See an example with **XML**: ```PHP setRoutesFromXml(__DIR__, 'routes.xml'); if ($routeMatch = $Routing->matchRoute()) { echo "See that" . "
"; var_dump($routeMatch); } else { echo "mmm.. what's wrong?"; } ``` And see a XML routes configuration file: ```XML <root> <node> <expression>/</expression> <controller>MyController</controller> <action>MyAction</action> <extra>Hello</extra> </node> <node> <expression>/contacts</expression> <controller>MyController2</controller> <params>Hello1</params> <extra> <name>Marco</name> <surname>Cante</surname> </extra> </node> </root>

Note: If you want use a XML file routes configuration, you must install the libxml php extension. You can see that, (*7)

Wildcards

A wildcard is a jolly name inserting into {} (like {idUser}). You can set wildcards into expression key/tag and set a requirements array key/tag for each one of them (see the example on bottom)., (*8)

If requirements array is not present for a wildcard, it can be everything. For example:, (*9)

'expression'    => '/{myName}'

It can be everything: * /marco * /123 * /marco123, (*10)

If requirements array is present for a wildcard, you can use a custom regular expression or ExpressionRoute static constant for NUMERIC or STRING (only in PHP array) strong expression. For example :, (*11)

'expression'    => '/{myName}',
'requirements'  => array(
    'myName'  => ExpressionRoute::STRING
    )

It can be: * /marco * /wellName, (*12)

But not: * /123 * /marco123, (*13)

And with custom regular expression:, (*14)

'expression'    => '/{myName}',
'requirements'  => array(
    'myName'  => (marco|luigi)
    )

It can be: * /marco * /luigi, (*15)

and not else! See the examples on bottom:, (*16)

Wildcards in Array

See an example with array:, (*17)

setRoutes(array(
    'homepage' => array(
        'expression'    => '/{wildcard}/{wildcard2}',
        'requirements'  => array(
            'wildcard'  => ExpressionRoute::NUMERIC,
            'wildcard2' => '(hello|bye)'
            ),
        'controller'    => 'MyController',
        'action'        => 'MyAction',
        'extra1'        => 'extra1',
    )
));

if ($routeMatch = $Routing->matchRoute()) {
    echo "See my data!";
    var_dump($routeMatch);
} else {
    echo "mmm.. what's wrong?";
}
```

### Wildcards in YML
See an example with **YML**:

```YML
homepage: 
    expression:   "/{test}"
    requirements:
        test:     "[a-zA-Z]+"
    controller:   "IndexController"
    action:       "showHomeAction"
    params:       ["myFirstParameter", "sendMe"]
```

### Wildcards in XML
See an example with **XML**:

```XML

<root>
  <node>
    <expression>/{test}</expression>
    <requirements>
      <test>(marco|luigi)</test>
    </requirements>
    <controller>MyController</controller>
    <action>MyAction</action>
  </node>
</root>

Unit Test

You can run unit test from document root with:, (*18)

vendor/bin/phpunit

The Versions

13/06 2017

dev-master

9999999-dev

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

13/06 2017

2.0.0

2.0.0.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

29/03 2017

1.1.1

1.1.1.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

28/03 2017

1.1.0

1.1.0.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

18/03 2017

1.0.2

1.0.2.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

18/03 2017

1.0.1

1.0.1.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

03/03 2017

1.0.0

1.0.0.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.6

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

01/03 2017

0.5.0

0.5.0.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

01/03 2017

0.4.0

0.4.0.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

01/03 2017

0.3.1

0.3.1.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

28/02 2017

0.3.0

0.3.0.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

26/02 2017

0.2.3

0.2.3.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

26/02 2017

0.2.2

0.2.2.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

26/02 2017

0.2.1

0.2.1.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

25/02 2017

0.2.0

0.2.0.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marco Cante

routing match route generate routes route manager

25/02 2017

0.1.0

0.1.0.0

PHP performance-oriented routing manager

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

by Marco Cante

routing match route generate routes route manager