Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/edsonbonfim/php-http-router
A fast and powerful router that maps route callbacks to specific HTTP request methods and URIs. It supports parameters and pattern matching
https://github.com/edsonbonfim/php-http-router
php php-router php7 psr-7 router routing
Last synced: about 1 month ago
JSON representation
A fast and powerful router that maps route callbacks to specific HTTP request methods and URIs. It supports parameters and pattern matching
- Host: GitHub
- URL: https://github.com/edsonbonfim/php-http-router
- Owner: edsonbonfim
- License: mit
- Created: 2018-03-09T10:10:47.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-12-12T00:08:01.000Z (about 5 years ago)
- Last Synced: 2024-04-22T04:47:06.496Z (8 months ago)
- Topics: php, php-router, php7, psr-7, router, routing
- Language: PHP
- Homepage:
- Size: 54.7 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Router
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]](LICENSE.md)
[![Build Status][ico-travis]][link-travis]
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-downloads]## Install
Via Composer
``` bash
$ composer require bonfim/router
```Basic Usage
-----------Include the autoloader of composer:
```php
name = 'Edson Onildo';
}public function hello()
{
echo 'Hello, {$this->name}!';
}
}$greeting = new Greeting();
Route::get('/', [$greeting, 'hello']);
```Routes are matched in the order they are defined. The first route to match a request will be invoked.
Method Routing
--------------The router allows you to register routes that respond to any HTTP verb:
```php
Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);
```You may register a route that responds to multiple verbs using the ```match``` method:
```php
Route::match(['get', 'post'], '/', function() {
//
});
```Or, you may even register a route that responds to all HTTP verbs using the ```any``` method:
```php
Route::any('/', function() {
//
});
```Named Parameters
----------------You may specify named parameters in your routes which will be passed along to your callback function:
```php
Route::get('/@name/@id', function($name, $id) {
echo "hello, $name ($id)!";
});
```You can also include regular expressions with your named parameters by using the : delimiter:
```php
Route::get('/@name/@id:[0-9]{3}', function($name, $id) {
// This will match /bob/123
// But will not match /bob/12345
});
```## Change log
Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.
## Testing
``` bash
$ composer test
```## Contributing
Please see [CONTRIBUTING](CONTRIBUTING.md) and [CODE_OF_CONDUCT](CODE_OF_CONDUCT.md) for details.
## Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
## Credits
- [Edson Onildo][link-author]
- [All Contributors][link-contributors]## License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
[ico-version]: https://img.shields.io/packagist/v/bonfim/router.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/BonfimLabs/PHP-HTTP-Router/master.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/BonfimLabs/PHP-HTTP-Router.svg?style=flat-square
[ico-code-quality]: https://img.shields.io/scrutinizer/g/BonfimLabs/PHP-HTTP-Router.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/bonfim/router.svg?style=flat-square[link-packagist]: https://packagist.org/packages/bonfim/router
[link-travis]: https://travis-ci.org/BonfimLabs/PHP-HTTP-Router
[link-scrutinizer]: https://scrutinizer-ci.com/g/BonfimLabs/PHP-HTTP-Router/code-structure
[link-code-quality]: https://scrutinizer-ci.com/g/BonfimLabs/PHP-HTTP-Router
[link-downloads]: https://packagist.org/packages/bonfim/router
[link-author]: https://github.com/EdsonOnildoJR
[link-contributors]: ../../contributors