Acksop / EdgeAltoRouter

PHP routing class with a config file. Lightweight yet flexible. Supports REST, dynamic and reversed routing.

Home Page:https://dannyvankooten.github.io/AltoRouter/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

EdgeAltoRouter PHP status

EdgeAltoRouter is a small but powerful routing class, forked from dannyvankooten.php with an important addition : a config model file.

$router = new EdgeAltoRouter(configModelUrl : __DIR__ . DIRECTORY_SEPARATOR . 'route.config');
$router->setBasePath(BASE_PATH);

$match = $router->match();

/*
 * $match may is like :
 * [
 *   'target' => 'home#index',
 *   'params' => [],
 *   'name' => 'home'
 * ]
 */

if( is_array($match) && is_callable( $match['target'] ) ) {
    call_user_func_array( $match['name'], $match['params'] ); 
} else {
    // no route was matched
    header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}


// echo URL to home at index
echo $router->generate('home'); // Output: "home#index"

Features

  • Can be used with all HTTP Methods
  • Dynamic routing with named route parameters
  • Reversed routing
  • Flexible regular expression routing (inspired by Sinatra)
  • Custom regexes
  • Support a config file who is like Yaml
  • Configure your style of use : Memory or Speed

Getting started

You need PHP >= 8.0 to use EdgeAltoRouter, although we highly recommend you use an officially supported PHP version that is not EOL.

Official Documentation of the forked AltoRouter

Contributors

License

MIT License

Copyright (c) 2012 Danny van Kooten hi@dannyvankooten.com

Addition/modification 2024 ROY Emmanuel emmanuel.roy@infoartsmedia.fr

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

PHP routing class with a config file. Lightweight yet flexible. Supports REST, dynamic and reversed routing.

https://dannyvankooten.github.io/AltoRouter/

License:MIT License


Languages

Language:PHP 100.0%