2017 © Pedro Peláez
 

library php-routes

Routing for PHP projects

image

sidvind/php-routes

Routing for PHP projects

  • Saturday, May 27, 2017
  • by ext
  • Repository
  • 1 Watchers
  • 0 Stars
  • 241 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 15 Versions
  • 14 % Grown

The README.md

PHP-routes

PHP Coverage Status Documentation, (*1)

Routing for MVC-ish PHP projects., (*2)

composer require sidvind/php-routes

Example

Put routes in a separate file, e.g. routes.php:, (*3)

<?php
/* basic routes */
$get('foo', ['to' => 'MyController#foo']);
$post('bar/:id/baz', ['to' => 'MyController#update']); /* use :var for variables */

/* automatically setup RESTful routes */
$resource('article', [], function($r){
  $r->members(function($r){
    $r->patch('frobnicate'); /* maps to PATCH /article/:id/frobnicate */
  });
  $r->collection(function($r){
    $r->patch('twiddle'); /* maps to PATCH /article/twiddle */
  });
});

/* scoping */
$scope(':lang', [], function($r){
  $r->get('barney'); /* maps to GET /:lang/barney */
});

Create a dispatcher:, (*4)

<?php
class Dispatcher extends Sidvind\PHPRoutes\Router {
    public function dispatch($url, $method){
        if ( $match = $this->match($url, $method) ){
            $class = "{$match->controller}Controller";
            $controller = new $class();
            return call_user_func_array([$controller, $match->action], $match->args);
        } else {
          /* 404 */
        }
    }
}
$router = new Dispatcher('routes.php');
$router->dispatch($url, $method);

To preview/debug routes use bin/php-routes:, (*5)

# bin/php-routes routes.php
        GET    /foo             MyController#foo      #^/foo(?P<format>\.\w+)?$#
        POST   /bar/:id/baz     MyController#update   #^/bar/(?P<id>[A-Za-z0-9\-_\.]+)/baz(?P<format>\.\w+)?$#
article GET    /article         Article#list          #^/article(?P<format>\.\w+)?$#
...
# bin/php-routes routes.php get /foo
Controller: MyController
Action: foo
Format:
Arguments:
[]
# bin/php-routes routes.php get /bar
bin/php-routes: url doesn't match any route.

The Versions

27/05 2017

dev-master

9999999-dev

Routing for PHP projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

rest route routing dispatch

27/05 2017

v1.4.2

1.4.2.0

Routing for PHP projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

rest route routing dispatch

13/04 2017

v1.4.1

1.4.1.0

Routing for PHP projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

rest route routing dispatch

09/04 2017

v1.4.0

1.4.0.0

Routing for PHP projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

rest route routing dispatch

02/04 2017

dev-feature/readthedocs2

dev-feature/readthedocs2

Routing for PHP projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

rest route routing dispatch

23/03 2017

v1.3.0

1.3.0.0

Routing for PHP projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

rest route routing dispatch

25/10 2016

v1.2.7

1.2.7.0

Routing for PHP projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

rest route routing dispatch

14/07 2016

v1.2.5

1.2.5.0

Routing for PHP projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

rest route routing dispatch

09/07 2016

v1.2.4

1.2.4.0

Routing for PHP projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

rest route routing dispatch

09/07 2016

v1.2.3

1.2.3.0

Routing for MVC-ish projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

09/07 2016

v1.2.2

1.2.2.0

Routing for MVC-ish projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

09/07 2016

v1.2.1

1.2.1.0

Routing for MVC-ish projects

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.6.0

 

The Development Requires

by David Sveningsson

02/07 2016

v1.2.0

1.2.0.0

Routing for MVC-ish projects

  Sources   Download

BSD-3-Clause

The Requires

 

by David Sveningsson

13/11 2015

v1.1.0

1.1.0.0

Routing for MVC-ish projects

  Sources   Download

BSD-3-Clause

by David Sveningsson

12/11 2015

v1.0.0

1.0.0.0

Routing for MVC-ish projects

  Sources   Download

BSD-3-Clause

by David Sveningsson