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! If you like, order a star for me~ ⭐, (*1)

一个简单快速的路由,使用树形结构存储匹配更快! 如果你喜欢,帮我点个star吧~ ⭐, (*2)

中文说明, (*3)

Latest Stable Version Total Downloads License, (*4)

Install

To install it via composer, (*5)

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! \( ^▽^ )/, (*6)

Tests

composer run-script test

Jetbrains, (*7)

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