diff --git a/README.md b/README.md index b2825e5..0c12368 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ Supported features: * **v4.x.x (LTS)** * v3.x.x (Unsupported) - -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. +* v2.x.x (Unavailable) +* v1.x.x (Unavailable) ## Installation @@ -70,7 +70,6 @@ After the configurations mentioned above, you can start using PhpRouter in your ```php use MiladRahimi\PhpRouter\Router; -use Zend\Diactoros\Response\JsonResponse; $router = new Router(); @@ -78,18 +77,10 @@ $router->get('/', function () { return '

This is homepage!

'; }); -$router->post('/blog/post/{id}', function ($id) { - return HtmlResponse("

This is a post $id

"); -}); - -$router->patch('/json', function () { - return new JsonResponse(["message" => "posted data to user: $id"]); -}); - $router->dispatch(); ``` -There are more examples [here](https://github.com/miladrahimi/phprouter/blob/master/examples/index.php). +There are more examples [here](https://github.com/miladrahimi/phprouter/tree/master/examples). ## HTTP Methods @@ -266,7 +257,7 @@ $router->dispatch(); ## HTTP Request and Request -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. +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. ### Request @@ -368,9 +359,9 @@ interface Middleware } ``` -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. +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. -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. +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. ```php use MiladRahimi\PhpRouter\Router; diff --git a/composer.json b/composer.json index faf9bc7..da5ad13 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "miladrahimi/phprouter", - "description": "PhpRouter is a powerful and standalone HTTP URL router for PHP projects.", + "description": "PhpRouter is a powerful, standalone, and very fast HTTP URL router for PHP projects.", "keywords": [ "Router", "URL Router", diff --git a/examples/example-01/index.php b/examples/example-01/index.php index 3143c94..90a6f87 100644 --- a/examples/example-01/index.php +++ b/examples/example-01/index.php @@ -3,7 +3,6 @@ require('../../vendor/autoload.php'); use MiladRahimi\PhpRouter\Router; -use Zend\Diactoros\Response\JsonResponse; $router = new Router(); @@ -11,8 +10,4 @@ return '

This is homepage!

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