izniburak / router
simple router class for php
Fund package maintenance!
izniburak
buymeacoff.ee/izniburak
Installs: 14 777
Dependents: 7
Suggesters: 0
Security: 0
Stars: 236
Watchers: 18
Forks: 45
Open Issues: 10
Requires
- php: ^8.1
- ext-json: *
- symfony/http-foundation: ^6.4
Requires (Dev)
- phpunit/phpunit: ^8.5 || ^9.4
This package is auto-updated.
Last update: 2024-11-14 01:54:24 UTC
README
_____ _ _ _____ _____ _
| __ \| | | | __ \ | __ \ | |
| |__) | |__| | |__) | ______ | |__) |___ _ _| |_ ___ _ __
| ___/| __ | ___/ |______| | _ // _ \| | | | __/ _ \ '__|
| | | | | | | | | \ \ (_) | |_| | || __/ |
|_| |_| |_|_| |_| \_\___/ \__,_|\__\___|_|
PHP Router, which also has rich features like Middlewares and Controllers is simple and useful router class for PHP.
Features
- Supports GET, POST, PUT, DELETE, OPTIONS, PATCH, HEAD, AJAX and ANY request methods
- Easy access and manage Request and Response via
symfony/http-foundation
package. - Controllers support (Example: HomeController@about)
- Before and after Route Middlewares support
- Static Route Patterns
- Dynamic Route Patterns
- Easy-to-use patterns
- Adding a new pattern supports. (with RegExp)
- Namespaces supports.
- Group Routing
- Custom 404 and Exception handling
- Debug mode (Error message open/close)
Install
To install PHP Router, You can run the following command directly at your project path in your console:
$ composer require izniburak/router
OR you can add following lines into the composer.json
file manually:
{ "require": { "izniburak/router": "^2.0" } }
Then, run the following command:
$ composer install
Example Usage
require 'vendor/autoload.php'; use Buki\Router\Router; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; $router = new Router; // For basic GET URI $router->get('/', function(Request $request, Response $response) { $response->setContent('Hello World'); return $response; # OR # return 'Hello World!'; }); // For basic GET URI by using a Controller class. $router->get('/test', 'TestController@main'); // For auto discovering all methods and URIs $router->controller('/users', 'UserController'); $router->run();
Docs
Documentation page: Buki\Router Docs
Changelogs: Buki\Router Changelogs
Support
Licence
Contributing
- Fork it ( https://github.com/izniburak/php-router/fork )
- Create your feature branch (git checkout -b my-new-feature)
- Commit your changes (git commit -am 'Add some feature')
- Push to the branch (git push origin my-new-feature)
- Create a new Pull Request
Contributors
- izniburak İzni Burak Demirtaş - creator, maintainer