Download the PHP package lefodeurcou/crazy-router without Composer
On this page you can find all versions of the php package lefodeurcou/crazy-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download lefodeurcou/crazy-router
More information about lefodeurcou/crazy-router
Files in lefodeurcou/crazy-router
Package crazy-router
Short Description A fast router with great possibilities
License MIT
Informations about the package crazy-router
Crazy-Router
🐘 A php based router. Simple and fast.
Crazy-Router is just a router.
It is designed to be as simple as possible and as fast as possible too.
🔌 Installation
Prerequisite
PHP >= 8.0 Composer >= 2.0
All requests must be redirected to your index.php (see Nginx or Apache configuration).
Composer
composer init
composer require lefodeurcou/crazy-router
💻 Usage
Features
Add how many routes you want
For the moment, this method is only a side effect method.
- method is http method represented by constants :
- Crazy\Router::GET
- Crazy\Router::POST
- Crazy\Router::PUT
- Crazy\Router::PATCH
- Crazy\Router::DELETE
- route is the path after the domain name like
/
,/path
or/path/for/the/truth
Routes can be parametrized like that :/user/{id}
where{id}
is an unknown value that can be getted back in callable (see below). -
callable is the function or the method that will be called if the route match the URL. Can be like :
funtion($params) {}
orfunction($params) use ($someVariable) {}
'functionName'
[$objectInstance, 'methodName']
The callable must take one parameter :$params
that contain all unknown values from the parametrized route. To access these values you must use$params
as associative array with keys that correspond to the route parameters, like that (see above at route):
-
patterns is an array that have to contain one pattern for each route parameter, like that :
If there is more patterns than parameters, they will be ingored. If there is less patterns than parameters, route will be ignored.
In php you can have a comma for last input of an array. It's ok.
- name is a string that allow you to retrive the route if you crawl the routes array given by
getAllRoutes
method. It's the less usefull parameter for the moment, but in a next version it could be used to trigger the callable of a named route trougth an other route, by example.
Get all routes with ...
Return an array that contains all route added earlier. Obviously 😎
Run, for a long time
Run the router, then it try to match a route with current URL. If it do, it run a corresponding callable. If it don't, it run $default
callable if it's provided. That's all.
Examples
Simple boilerplate
With function declared before, and one parameter
With a method from a class
🔧 Devlopment
Unix environment is recommended and more again a linux distribution.
There is two bash script for units tests and benchmarks tests.
Except these, you can use what you want.
Units Tests
It use PHPUnit for it.
There is a bash script unit
to launch tests.
Benchmarks
It use PHPBench for it.
There is a bash script bench
to launch tests.
🔐 License
MIT
📢 Last word
Don't forget, be crazy 💥💥💥