Download the PHP package gac/routing without Composer
On this page you can find all versions of the php package gac/routing. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package routing
Short Description Custom routing library especially useful for fast API development
License GPL-3.0-only
Homepage https://github.com/gigili/PHP-routing
Informations about the package routing
Routing library for PHP
This library allows you to create static or dynamic routes. This library was inspired by PHP Slim framework
Install via composer
Manual install
Download the latest release from the Releases page.
Don't forget to add these include_once
statements to your php files:
Post install
To use this library properly you will need to create a .htaccess
file at the root of the project.
Example of the .htaccess
file would look like this:
Note
If you've named your main file differently, replace index.php
in the .htaccess
file with whatever your main
application file is.
Quick start
Sample code to allow you to quickly start with your development.
Examples
Dynamic routes example
Chained routes
When using chained methods either use ->save()
or ->add()
as the last method to indicate the end of a chain
NOTE
->save(true|false)
method can still be chained onto if needed- Passing
false
(the default value istrue
) to the->save()
method will preserve all the previous prefixes and middlewares in that chain
- Passing
->add()
CAN NOT be chained onto and should be the last call in chain
Chained routes with save at the end
Chained routes with multiple chains in one call
Passing arguments to middleware methods
When working with middlewares you can also pass them arguments if you need to
Every middleware function can also accept an argument of type Gac\Routing\Request
at any position as long as it has
the proper type specified.
Optional parameters
When calling this endpoint with /demo
it will output ID: defaultValue
and with /demo/123
it will output ID: 123
Dependency injection on route classes
When using classes to handle your route callback, and those classes have some dependencies that need to be injected through a constructor, you can specify them as an array of arguments to be injected or let the library try to auto-inject classes.
You can also use named arguments or mix and match them
Letting the library auto-inject classes into the constructor
NOTE
The library will always try to auto-inject classes (will skip ones with null as default value) if non are provided, and you're using a class for callbacks.
Use __invoke
instead for single method classes
You can also use __invoke
with dependency injection as well:
For more examples look in the sample folder index.php
file
Documentation
Source code documentation can be found at PHP Routing documentation page
Features
- [x] Static routes
- [x] Dynamic routes
- [x] Dynamic routes with optional parameters
- [x] Middlewares
- [x] Pass arguments to middlewares
- [x] Route prefixes
- [x] Method chaining
- [x] Dependency injection on classes
- [x] Manual injection
- [x] Auto-injection
All versions of routing with dependencies
ext-json Version *
ext-mbstring Version *