You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# A simple Router for PHP App using PSR-7 message implementation
1
+
# PHP Router : A versatile and efficient PHP routing solution designed to streamline route management within PHP applications.
2
2
3
3
[](https://packagist.org/packages/devcoder-xyz/php-router)[](https://packagist.org/packages/devcoder-xyz/php-router)[](https://packagist.org/packages/devcoder-xyz/php-router)[](https://packagist.org/packages/devcoder-xyz/php-router)[](https://packagist.org/packages/devcoder-xyz/php-router)
4
4
5
+
## Description
6
+
7
+
PHP Router is a simple and efficient routing library designed for PHP applications. It provides a straightforward way to define routes, handle HTTP requests, and generate URLs. Built with PSR-7 message implementation in mind, it seamlessly integrates with PHP applications.
8
+
9
+
5
10
## Installation
6
11
7
-
Use [Composer](https://getcomposer.org/)
12
+
You can install PHP Router via Composer. Just run:
- Flexible route definition with attribute constraints
123
+
- Exception handling for method not allowed and route not found scenarios
124
+
125
+
## Route Definition
126
+
127
+
Routes can be defined using the `Route` class provided by PHP Router. You can specify HTTP methods, attribute constraints, and handler methods for each route.
128
+
109
129
```php
110
130
$route = new \DevCoder\Route('api_articles_post', '/api/articles', [ArticleController::class, 'post'], ['POST']);
111
131
$route = new \DevCoder\Route('api_articles_put', '/api/articles/{id}', [ArticleController::class, 'put'], ['PUT']);
132
+
```
133
+
### Easier Route Definition with Static Methods
134
+
135
+
To make route definition even simpler and more intuitive, the `RouteTrait` provides static methods for creating different types of HTTP routes. Here's how to use them:
With these static methods, defining routes becomes a breeze, providing a smoother and more efficient way to handle routing in your PHP application.
230
+
231
+
### Using `where` Constraints in the Route Object
232
+
233
+
The `Route` object allows you to define constraints on route parameters using the `where` methods. These constraints validate and filter parameter values based on regular expressions. Here's how to use them:
234
+
235
+
#### Method `whereNumber()`
236
+
237
+
This method applies a numeric constraint to the specified route parameters.
238
+
239
+
```php
240
+
/**
241
+
* Sets a number constraint on the specified route parameters.
242
+
*
243
+
* @param mixed ...$parameters The route parameters to apply the constraint to.
0 commit comments