Skip to content

felipecwb/Routing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Routing

Build Status Latest Stable Version License

More one simple Routing library for PHP.

You'll need know about Regex Patterns.

Instalation

Composer:

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

Example:

<?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;

Look in tests for more explanation

Contributions

Feel free to contribute.

  1. Create a issue.
  2. Follow the PSR-2 and PSR-4
  3. PHPUnit to tests

License MIT

About

More One Simple Router for PHP.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages