2017 © Pedro Peláez
 

library php-routing

Emerge PHP Routing

image

emerge/php-routing

Emerge PHP Routing

  • Sunday, March 6, 2016
  • by emerge
  • Repository
  • 1 Watchers
  • 1 Stars
  • 225 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 9 % Grown

The README.md

简介

一个基础的PHP路由, (*1)

安装

composer require emerge/php-routing

快速入门

use Emerge\Routing;

$routing = new Routing();

$routing->get(
    '/admin',
    ['App\Admin', 'index']
);

$routing->get(
    '/admin/user/$id',
    ['App\Admin', 'index'],
    [
        'requirements' => [
            'id' => '\d+'
        ]
    ]
);

$result = $routing->dispatch('GET', '/admin/user/1');

print_r($result);

输出内容, (*2)

Array
(
    [route] => /admin/user/$id

    [callback] => Array
    (
        [0] => App\Admin
        [1] => index
    )

    [options] => Array
    (
        [requirements] => Array
        (
            [id] => \d+
        )

        [method] => Array
        (
            [0] => GET
        )
    )

    [parameters] => Array
    (
        [0] => /admin/user/1
        [id] => 1
        [1] => 1
    )
)

常量

VERSION

string
版本号, (*3)

$routing::VERSION

API

get - 路由设置

array get (string $route, array|callable $callback, [array $options = []])
返回添加的路由数据, (*4)

参数

route, (*5)

路由路径, (*6)

callback, (*7)

路由回调,参考链接, (*8)

options, (*9)

路由选项, 支持 requirements,method 两个选项, (*10)

返回值

Array
(
    [route] => /admin/user/$id

    [callback] => Array
    (
        [0] => App\Admin
        [1] => index
    )

    [options] => Array
    (
        [requirements] => Array
        (
            [id] => \d+
        )

        [method] => Array
        (
            [0] => GET
        )
    )
)

示例

$routing->get(
    '/admin/user/$id',
    ['App\Admin', 'index'],
    [
        'method' => ['GET', 'POST']
        'requirements' => [
            'id' => '\d+'
        ]
    ]
);

dispatch - 分派路由

array dispatch (string $method, string $uri)
返回路由分派结果, (*11)

参数

method, (*12)

HTTP方法, (*13)

uri, (*14)

URI, (*15)

返回值

Array
(
    [route] => /admin/user/$id

    [callback] => Array
    (
        [0] => App\Admin
        [1] => index
    )

    [options] => Array
    (
        [requirements] => Array
        (
            [id] => \d+
        )

        [method] => Array
        (
            [0] => GET
        )
    )

    [parameters] => Array
    (
        [0] => /admin/user/1
        [id] => 1
        [1] => 1
    )
)

示例

$result = $routing->dispatch('GET', '/admin/user/1');

The Versions

06/03 2016

dev-master

9999999-dev

Emerge PHP Routing

  Sources   Download

MIT

The Development Requires

by 高翔

06/03 2016

0.1.1

0.1.1.0

Emerge PHP Routing

  Sources   Download

MIT

The Development Requires

by 高翔

29/11 2015

0.1.0

0.1.0.0

Emerge PHP Routing

  Sources   Download

MIT

The Development Requires

by 高翔