Download the PHP package jameslevi/dispatcher without Composer
On this page you can find all versions of the php package jameslevi/dispatcher. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download jameslevi/dispatcher
More information about jameslevi/dispatcher
Files in jameslevi/dispatcher
Package dispatcher
Short Description Is a simple routing engine for PHP applications.
License MIT
Informations about the package dispatcher
Dispatcher
Is a simple routing engine for PHP applications.
Features
- Supports GET, POST, PUT, PATCH, DELETE and HEAD method.
- Enables you to inject event-based callbacks.
- Before and after middleware support.
- Lightweight and easy to use.
Installation
-
You can install via composer.
- Add the composer autoload mechanism if not using any framework.
Basic Implementation
Request Methods
GET - Retrieve resource representation/information.
POST - Create new resource.
PUT - Update existing resource.
PATCH - Make a partial update on a resource.
DELETE - Delete a resource.
HEAD - Request method identical to GET method but has no body.
Multiple Method Support
Any - Route that can use any request method.
Match - Multiple request method support.
Event Callbacks
Create - Triggered at the beginning of the request.
Before Middleware - Triggered before the middleware handler iteration.
Middleware - Triggered each time a middleware is called.
Middleware Abort - Triggered each time abort is called inside a middleware.
Before Action - Triggered before doing the route action.
After Action - Triggered after doing the route action.
Body Sent - Triggered when the response body was sent.
Destroy - Triggered at the very end of the request.
Error - Triggered each time error occurs.
Route Matched - Triggered if request route matches.
Error Handling
You can set default error callback for all errors.
You can also set callback for each error code.
Before Middlewares
You can implement multiple middlewares before doing the request action.
You can also implement middleware callbacks using classes.
You can now use this class as your middleware.
After Middlewares
You can also implement multiple middlewares after doing the route action.
Actions
This are things you wish to accomplish in each request.
Controllers
Instead of defining all actions in a closure, you may wish to organize everything inside a controller class.
GET Parameters
You can access all the GET parameters using the get method from the request object.
POST, PUT, PATCH, DELETE Parameters
You can use the "post" method from the request object to retrieve POST parameters.
URI Embeded Parameters
You can also use segment of the request URI as a parameter.
Forced Abort
You can immediately terminate the request using "abort" method.
Headers
You can assign headers using the "setHeader" method.
Service Availability
You can down the service availability using the "down" method.
You can also down individual routes.
Request Helpers
Method - Return the request method used during the request.
URI - Return the current request uri excluding the query string.
Port - Return the server port number.
Protocol - Return the server protocol.
Secure - Determine if request is through secure connection.
Localhost - Determine if request is in localhost.
XMLHttpRequest - Determine if request is using XMLHttpRequest.
Contribution
For issues, concerns and suggestions, you can email James Crisostomo via [email protected].
License
This package is an open-sourced software licensed under MIT License.