felipecwb/routing

PHP的一个更简单的路由器。

v0.4 2014-12-19 01:18 UTC

This package is not auto-updated.

Last update: 2024-09-24 02:39:11 UTC


README

Build Status Latest Stable Version License

一个更简单的PHP路由库。

你需要了解正则表达式模式

安装

Composer:

{
    "felipecwb/routing": "dev-master"
}

示例:

<?php

use Felipecwb\Routing\Router;
// Exceptions
use Felipecwb\Routing\Exception\ResolverException;
use Felipecwb\Routing\Exception\RouteNotFoundException;

$router = Router::create();

$router->add('/', function () {
    echo "Hello World!";
});

$router->add('/hello/(\w+)', function ($name) {
    echo "Hello {$name}!";
});

$router->add('/article/(\d+)', function ($id, $extraStr) {
    echo "Article {$id}! ${extraStr}";
});

try {
    $router->dispatch('/');
    // with arguments
    $router->dispatch('/hello/felipecwb');
    // with extra arguments
    $router->dispatch('/hello/10', ['Extra String!']);
} catch (RouteNotFoundException $e) {
    echo "Sorry! The target can not be found!";
} catch (ResolverException $e) {
    echo "Sorry! The target can not be executed!";
}

die;

查看测试以获取更多说明

贡献

请随时贡献。

  1. 创建一个问题。
  2. 遵循PSR-2和PSR-4
  3. 使用PHPUnit进行测试

许可证MIT