This repository has been archived by the owner on Jan 31, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
174 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
# Introduction | ||
|
||
zend-router is a HTTP router implementation for | ||
[PSR-7 HTTP message interfaces](http://www.php-fig.org/psr/psr-7/). | ||
It provides dynamic routing capabilities required in most modern web | ||
applications using literal and dynamic path segments, domain, method and scheme | ||
matching. | ||
|
||
## Routing | ||
|
||
Routing refers to matching request URI or other request information using | ||
defined rules(routes) in order to determine an appropriate handler for the | ||
request and to extract matched values. | ||
|
||
Zend-router defines `match()` method that accepts PSR-7 server request and | ||
returns `Zend\Router\RouteResult` instance to indicate the result of the | ||
matching operation. | ||
|
||
`RouteResult` provides three methods to check the outcome: | ||
- `isSuccess()` will be true when route successfully matched | ||
- `isFailure()` will be true when none of the routes matched | ||
- `isMethodFailure()` will be true when some routes could match but with | ||
different HTTP method. List of allowed HTTP methods is also provided with | ||
`getAllowedMethods()` | ||
|
||
## Retrieving matched parameters | ||
|
||
When routing is successful, result will contain list of matched or default | ||
parameters: | ||
|
||
```php | ||
$parameters = $result->getMatchedParams(); | ||
``` | ||
|
||
Typically, application utilizing zend-router would inject matched parameters | ||
into request as *attributes*: | ||
|
||
```php | ||
$id = $request->getAttribute('id'); | ||
``` | ||
|
||
## Retrieving matched route name | ||
|
||
When routing is successful, result will also contain a name of the route that | ||
matched: | ||
|
||
```php | ||
$routeName = $result->getMatchedRouteName(); | ||
``` | ||
|
||
## URI generation | ||
|
||
Because router have knowledge of the various paths it can match, it is | ||
also typically used within applications to generate URIs to other application | ||
resources, avoiding the need to hardcode them. | ||
|
||
You can call the `assemble()` method with a route name and a list of parameters | ||
and options to be used for URI assembling. Router will return intance of | ||
PSR-7 `UriInterface`: | ||
|
||
```php | ||
$uri = $router->assemble('routename', ['id' => '123'], ['query' => ['p' => 2]]); | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Migrating from v3 to v4 | ||
|
||
zend-router v4 makes a number of significant changes that will affect your | ||
application. This document details those changes, and provides suggestions on | ||
how to update your application to work with v3. | ||
|
||
## PSR-7 Rewrite | ||
|
||
zend-router drops support for `Zend\Stdlib\RequestInterface` and switches to | ||
[PSR-7 HTTP message interfaces](http://www.php-fig.org/psr/psr-7/) | ||
`Psr\Http\Message\ServerRequestInterface`. That means that non-HTTP routing is | ||
no longer supported. | ||
|
||
## Backward incompatible changes | ||
|
||
- `Zend\Router\Http\TreeRouteStack` was moved to `Zend\Router\TreeRouteStack` | ||
- `RouteInterface::match()` method now accepts `Psr\Http\Message\ServerRequestInterface` | ||
and always returns `Zend\Router\RouteResult`. | ||
- `RouteInterface::assemble()` accepts same arguments as before, except for `'uri'` option, which | ||
must be instance of `Psr\Http\Message\UriInterface` if present. | ||
Returns instance of `Psr\Http\Message\UriInterface` or throws if route cannot | ||
be assembled. | ||
- `Zend\Route\RouteMatch` is removed and replaced with `Zend\Router\RouteResult` | ||
- `RouteInterface::match()` method is no longer allowed to return partial match. | ||
`Zend\Router\PartialRouteInterface` is introduced to provide that functionality. | ||
`Chain`, `Hostname`, `Literal`, `Method`, `Regex`, `Scheme` and `Segment` | ||
routes are now partial routes. | ||
- `Chain` route now accepts partial routes only | ||
- `Part` route now requires partial route for its base route. | ||
- Base path support was dropped from the router. It is now responsibility of an | ||
application and its url helpers. | ||
- Router no longer provides absolute URI populated from current request. It is | ||
now responsibility of application url helpers | ||
|
||
## Http routes namespace change | ||
|
||
In zend-router v3, HTTP specific routes were in `Zend\Router\Http` namespace. | ||
With v4 zend-router became HTTP only router so the namespace was changed to | ||
`Zend\Router\Route`. | ||
|
||
If you were referring routes using their fully qualified class names in router | ||
configuration you are urged to update your code. However, old FQCN are | ||
registered as aliases in RoutePluginManager and configuration will continue | ||
work unchanged. | ||
|
||
## Wildcard route removal | ||
|
||
`Zend\Router\Http\Wildcard` was deprecated starting in version 2.3.0. If you | ||
were using it previously, it no longer exists. Wildcard route is considered | ||
problematic, due to the fact that arbitrary route match parameters may be | ||
specified, which could potentially lead to nefarious actions such as selection | ||
of an alternate controller or controller action. | ||
|
||
|
||
## Console routing | ||
|
||
Console routing support was dropped from zend-router for version 4. If you use | ||
zend-mvc-console, you will need to migrate to standalone console application | ||
such as `zfcampus/zf-console` or `symfony/console` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters