Skip to content

Commit 00bc329

Browse files
committed
Merge branch 'master' of github.com:miladrahimi/phprouter
2 parents debdff8 + 9ace566 commit 00bc329

File tree

3 files changed

+7
-21
lines changed

3 files changed

+7
-21
lines changed

README.md

+6-15
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ Supported features:
2424

2525
* **v4.x.x (LTS)**
2626
* v3.x.x (Unsupported)
27-
28-
The versions *v2* and *v1* are not available in this repository, please consider an upgrade to the newer versions if you are still using them.
27+
* v2.x.x (Unavailable)
28+
* v1.x.x (Unavailable)
2929

3030
## Installation
3131

@@ -70,26 +70,17 @@ After the configurations mentioned above, you can start using PhpRouter in your
7070
7171
```php
7272
use MiladRahimi\PhpRouter\Router;
73-
use Zend\Diactoros\Response\JsonResponse;
7473
7574
$router = new Router();
7675
7776
$router->get('/', function () {
7877
return '<p>This is homepage!</p>';
7978
});
8079
81-
$router->post('/blog/post/{id}', function ($id) {
82-
return HtmlResponse("<p>This is a post $id</p>");
83-
});
84-
85-
$router->patch('/json', function () {
86-
return new JsonResponse(["message" => "posted data to user: $id"]);
87-
});
88-
8980
$router->dispatch();
9081
```
9182

92-
There are more examples [here](https://github.com/miladrahimi/phprouter/blob/master/examples/index.php).
83+
There are more examples [here](https://github.com/miladrahimi/phprouter/tree/master/examples).
9384

9485
## HTTP Methods
9586

@@ -266,7 +257,7 @@ $router->dispatch();
266257

267258
## HTTP Request and Request
268259

269-
PhpRouter uses [zend-diactoros](https://github.com/zendframework/zend-diactoros) package (v2) to provide [PSR-7](https://www.php-fig.org/psr/psr-7) complaint request and response objects to your controllers and middleware.
260+
PhpRouter uses [zend-diactoros](https://github.com/zendframework/zend-diactoros) package (v2) to provide [PSR-7](https://www.php-fig.org/psr/psr-7) request and response objects to your controllers and middleware.
270261

271262
### Request
272263

@@ -368,9 +359,9 @@ interface Middleware
368359
}
369360
```
370361

371-
As you can see, a middleware must have a `handle()` method that catches the request and a Closure (which is responsible for running the next middleware or the controller). It must return a response, as well. A middleware can break the lifecycle and return the response or it can run the `$next` closure to continue the lifecycle.
362+
As you can see, a middleware must have a `handle()` method that catches the request and a Closure (which is responsible for running the next middleware or the controller). It must return a response, as well. A middleware can break the lifecycle and return a response or it can run the `$next` closure to continue the lifecycle.
372363

373-
See the following example. In this snippet, if there is an `Authorization` header in the request, it passes the request to the next middleware or the controller (if there is no more middleware left) and if the header is absent, it returns an empty response with `401 Authorization Failed ` HTTP status code.
364+
See the following example. In the implemented middelware, if there is an `Authorization` header in the request, it passes the request to the next middleware or the controller (if there is no more middleware left) and if the header is absent, it returns a JSON response with `401 Authorization Failed ` HTTP status code.
374365

375366
```php
376367
use MiladRahimi\PhpRouter\Router;

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "miladrahimi/phprouter",
3-
"description": "PhpRouter is a powerful and standalone HTTP URL router for PHP projects.",
3+
"description": "PhpRouter is a powerful, standalone, and very fast HTTP URL router for PHP projects.",
44
"keywords": [
55
"Router",
66
"URL Router",

examples/example-01/index.php

-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,11 @@
33
require('../../vendor/autoload.php');
44

55
use MiladRahimi\PhpRouter\Router;
6-
use Zend\Diactoros\Response\JsonResponse;
76

87
$router = new Router();
98

109
$router->get('/', function () {
1110
return '<p>This is homepage!</p>';
1211
});
1312

14-
$router->post('/api/user/{id}', function ($id) {
15-
return new JsonResponse(["message" => "posted data to user: $id"]);
16-
});
17-
1813
$router->dispatch();

0 commit comments

Comments
 (0)