2017 © Pedro Peláez
 

library routing

A routing use "symfony/routing" and like "laravel/routing" style

image

heropoo/routing

A routing use "symfony/routing" and like "laravel/routing" style

  • Monday, January 29, 2018
  • by heropoo
  • Repository
  • 1 Watchers
  • 5 Stars
  • 254 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 6 Versions
  • 1 % Grown

The README.md

routing

A simple and fast route.Use tree structure storage, fast matching! 一个简单快速的路由,使用树形结构存储匹配更快!, (*1)

中文说明, (*2)

Latest Stable Version Total Downloads License, (*3)

install

To install it via composer, (*4)

composer require heropoo/routing

feature

  • Support restful style route
  • Support route group and add some attributes (like namespace,middleware,prefix..)
  • Support route params and limit param's type
  • Support regex
  • Use tree structure storage, fast matching!

example:

<?php

require_once './vendor/autoload.php';

use Moon\Routing\Router;
use Moon\Routing\UrlMatchException;

$router = new Router([
    'namespace'=>'app\\controllers',    //support controller namespace
    'middleware'=>[                     //support middleware
        'startSession',
        'verifyCSRFToken',
        'auth'
    ],
    'prefix'=>''                        //support prefix
]);

// action also can be a Closure
$router->get('/', function(){
    return 'Welcome \( ^▽^ )/';
});

//route parameter
$router->get('/hello/{name}', function($name){ // auto pick route param to Closure 
    return 'Hello '.$name;
});

$router->get('/login', 'UserController::login', 'login'); // name your route
$router->post('login', 'UserController::post_login');

//use route group
$router->group(['prefix'=>'user'], function(Router $router){
    $router->post('delete/{id:\d+}', 'UserController::delete'); // {param:type pattern}
});

// match GET or POST request method
$router->match(['get', 'post'], '/api', 'ApiController::index');

// match all request method
$router->any('/other', 'ApiController::other');

// get all routes
var_dump($router->getRoutes());

/**
 * match request
 * @param string $path Request path, eg: /user/list
 * @param string $method Request method, 'GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS''GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE', 'OPTIONS'
 * @return array If not matched throw a UrlMatchException
 * return [
 *   'route' => $route,  // Route
 *   'params' => $params // array
 * ];
 *
 */
$res = $router->dispatch($path, $method);

var_dump($res);

Now use matched result to handle your controller's method or Closure! \( ^▽^ )/, (*5)

Jetbrains, (*6)

The Versions

29/01 2018

dev-master

9999999-dev

A routing use "symfony/routing" and like "laravel/routing" style

  Sources   Download

MIT

The Requires

 

by Avatar heropoo

29/01 2018

v0.5

0.5.0.0

A routing use "symfony/routing" and like "laravel/routing" style

  Sources   Download

MIT

The Requires

 

by Avatar heropoo

29/09 2017

v0.4

0.4.0.0

A routing use "symfony/routing" and like "laravel/routing" style

  Sources   Download

MIT

The Requires

 

by Avatar heropoo

22/08 2017

v0.3

0.3.0.0

A routing use "symfony/routing" and like "laravel/routing" style

  Sources   Download

MIT

The Requires

 

by Avatar heropoo

09/08 2017

v0.2

0.2.0.0

A routing use "symfony/routing" and like "laravel/routing" style

  Sources   Download

MIT

The Requires

 

by Avatar heropoo

08/08 2017

v0.1

0.1.0.0

A routing use "symfony/routing" and like "laravel/routing" style

  Sources   Download

MIT

The Requires

 

by Avatar heropoo