Download the PHP package refkinscallv/php-route without Composer
On this page you can find all versions of the php package refkinscallv/php-route. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download refkinscallv/php-route
More information about refkinscallv/php-route
Files in refkinscallv/php-route
Package php-route
Short Description PHP Routing Library provides a flexible and easy-to-use routing system for PHP applications
License MIT
Informations about the package php-route
PHP Route
PHP Route is a lightweight and flexible routing library for PHP applications. It provides an easy-to-use system for defining routes, grouping, middlewares, error handling, maintenance mode, and custom not-found responses.
Features
- Define routes with HTTP methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
- Support for
any()method to handle all HTTP methods - Route parameters with regex support and optional parameters
- Route grouping with optional prefix and middlewares
- Global, group, and route-specific middlewares with multiple format support
- Middleware closure with return value control (true = continue, false = stop)
- Support for closure, static class, and instance middleware formats
- Request attributes with middleware persistence - Set attributes in middleware, access in handlers
- Custom error handling and maintenance mode
- Custom 404 Not Found and maintenance responses
- PSR-7 compatible Request and Response objects using Guzzle
Installation
Install via Composer:
Include Composer autoloader in your project:
Basic Usage
Simple Routes
Route with Controller
Route Parameters
Required Parameters
Optional Parameters
Parameters with Regex Validation
Middleware System
Middleware Formats
PHP Route supports three middleware formats for maximum flexibility:
1. Closure/Anonymous Function
2. Static Class Method
3. Instance Method
Multiple Middlewares on Single Route
Middleware Control Flow
Middleware execution stops immediately when any middleware returns false:
Request Attributes
Setting Attributes in Middleware
Middleware can set attributes on the request object that persist to the route handler:
Accessing Attributes in Route Handlers
Attributes set by middleware are automatically available in route handlers:
Combining URL Parameters with Middleware Attributes
Complete Attribute Example
Global Middleware
Apply middleware to all routes within a callback:
Route Groups
Basic Group
Group with Middleware
Nested Groups
Error Handling
Global Error Handler
Not Found Handler (404)
Maintenance Mode
Request Object
Getting Input Data
Supported Content Types
application/json- Automatically parsedapplication/x-www-form-urlencoded- Form data- Multipart form data and file uploads
Response Object
Sending Responses
Complete Example
Contributing
Contributions are welcome! You can help by:
- Reporting bugs
- Suggesting features
- Submitting pull requests
Please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature-name) - Make your changes and commit (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature-name) - Open a Pull Request
Reporting Issues
If you encounter a bug or have a feature request, please open an issue on the GitHub repository. Include:
- A clear description of the problem
- Steps to reproduce the issue
- Any relevant error messages or stack traces
Version History
v1.0.7
- ✅ Added middleware closure with return value control (true/false)
- ✅ Support for multiple middleware formats (closure, static class, instance)
- ✅ Fixed optional parameter support with
{?param}syntax - ✅ Added request attribute persistence across middleware chain
- ✅ Middleware can now set attributes accessible in route handlers
- ✅ Improved middleware execution flow
- ✅ Full backward compatibility
v1.0.7
- Previous version
License
This library is licensed under the MIT License.