Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit f7bcf65

Browse files
committed
Merge branch 'hotfix/pipeline-config'
Close #270
2 parents 501adde + 734d89e commit f7bcf65

30 files changed

+2142
-861
lines changed

CHANGELOG.md

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,32 @@
22

33
All notable changes to this project will be documented in this file, in reverse chronological order by release.
44

5-
## 1.0.0 - TBD
6-
7-
First stable release.
5+
## 1.0.0rc6 - TBD
6+
7+
Sixth release candidate.
8+
9+
This release contains backwards compatibility breaks with previous release
10+
candidates. All previous functionality should continue to work, but will
11+
emit `E_USER_DEPRECATED` notices prompting you to update your application.
12+
In particular:
13+
14+
- The routing middleware has been split into two separate middleware
15+
implementations, one for routing, another for dispatching. This eliminates the
16+
need for the route result observer system, as middleware can now be placed
17+
*between* routing and dispatching — an approach that provides for greater
18+
flexibility with regards to providing route-based functionality.
19+
- As a result of the above, `Zend\Expressive\Application` no longer implements
20+
`Zend\Expressive\Router\RouteResultSubjectInterface`, though it retains the
21+
methods associated (each emits a deprecation notice).
22+
- Configuration for `Zend\Expressive\Container\ApplicationFactory` was modified
23+
to implement the `middleware_pipeline` as a single queue, instead of
24+
segregating it between `pre_routing` and `post_routing`. Each item in the
25+
queue follows the original middleware specification from those keys, with one
26+
addition: a `priority` key can be used to allow you to granularly shape the
27+
execution order of the middleware pipeline.
28+
29+
A [migration guide](http://zend-expressive.rtfd.org/en/latest/migration/rc-to-v1/)
30+
was written to help developers migrate to RC6 from earlier versions.
831

932
### Added
1033

@@ -24,14 +47,44 @@ First stable release.
2447
a flow/architectural diagram to the "features" chapter.
2548
- [#262](https://github.com/zendframework/zend-expressive/pull/262) adds
2649
a recipe demonstrating creating classes that can intercept multiple routes.
50+
- [#270](https://github.com/zendframework/zend-expressive/pull/270) adds
51+
new methods to `Zend\Expressive\Application`:
52+
- `dispatchMiddleware()` is new middleware for dispatching the middleware
53+
matched by routing (this functionality was split from `routeMiddleware()`).
54+
- `routeResultObserverMiddleware()` is new middleware for notifying route
55+
result observers, and exists only to aid migration functionality; it is
56+
marked deprecated!
57+
- `pipeDispatchMiddleware()` will pipe the dispatch middleware to the
58+
`Application` instance.
59+
- `pipeRouteResultObserverMiddleware()` will pipe the route result observer
60+
middleware to the `Application` instance; like
61+
`routeResultObserverMiddleware()`, the method only exists for aiding
62+
migration, and is marked deprecated.
63+
- [#270](https://github.com/zendframework/zend-expressive/pull/270) adds
64+
`Zend\Expressive\MarshalMiddlewareTrait`, which is composed by
65+
`Zend\Expressive\Application`; it provides methods for marshaling
66+
middleware based on service names or arrays of services.
2767

2868
### Deprecated
2969

30-
- Nothing.
70+
- [#270](https://github.com/zendframework/zend-expressive/pull/270) deprecates
71+
the following methods in `Zend\Expressive\Application`, all of which will
72+
be removed in version 1.1:
73+
- `attachRouteResultObserver()`
74+
- `detachRouteResultObserver()`
75+
- `notifyRouteResultObservers()`
76+
- `pipeRouteResultObserverMiddleware()`
77+
- `routeResultObserverMiddleware()`
3178

3279
### Removed
3380

34-
- Nothing.
81+
- [#270](https://github.com/zendframework/zend-expressive/pull/270) removes the
82+
`Zend\Expressive\Router\RouteResultSubjectInterface` implementation from
83+
`Zend\Expressive\Application`.
84+
- [#270](https://github.com/zendframework/zend-expressive/pull/270) eliminates
85+
the `pre_routing`/`post_routing` terminology from the `middleware_pipeline`,
86+
in favor of individually specified `priority` values in middleware
87+
specifications.
3588

3689
### Fixed
3790

doc/book/application.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,21 +186,24 @@ function ($error, ServerRequestInterface $request, ResponseInterface $response,
186186

187187
Read the section on [piping vs routing](router/piping.md) for more information.
188188

189-
### Registering routing middleware
189+
### Registering routing and dispatch middleware
190190

191-
Routing is accomplished via dedicated a dedicated middleware method,
192-
`Application::routeMiddleware()`. It is an instance method, and can be
193-
piped/registered with other middleware platforms if desired.
191+
Routing is accomplished via a dedicated middleware method,
192+
`Application::routeMiddleware()`; similarly, dispatching of routed middleware
193+
has a corresponding instance middleware method, `Application::dispatchMiddleware()`.
194+
Each can be piped/registered with other middleware platforms if desired.
194195

195-
Internally, the first time `route()` is called (including via one of the proxy
196-
methods), or, if never called, when `__invoke()` (the exposed application
197-
middleware) is called, the instance will pipe `Application::routeMiddleware` to
198-
the middleware pipeline. You can also pipe it manually if desired:
196+
These methods **MUST** be piped to the application so that the application will
197+
route and dispatch routed middleware. This is done using the following methods:
199198

200199
```php
201200
$app->pipeRoutingMiddleware();
201+
$app->pipeDispatchMiddleware();
202202
```
203203

204+
See the section on [piping](router/piping.md) to see how you can register
205+
non-routed middleware and create layered middleware applications.
206+
204207
## Retrieving dependencies
205208

206209
As noted in the intro, the `Application` class has several dependencies. Some of

doc/book/container/factories.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,20 @@ instance.
3535
When the `config` service is present, the factory can utilize several keys in
3636
order to seed the `Application` instance:
3737

38-
- `middleware_pipeline` can be used to seed pre- and/or post-routing middleware:
38+
- `middleware_pipeline` can be used to seed the middleware pipeline:
3939

4040
```php
4141
'middleware_pipeline' => [
42-
// An array of middleware to register prior to registration of the
43-
// routing middleware:
44-
'pre_routing' => [
45-
],
46-
// An array of middleware to register after registration of the
47-
// routing middleware:
48-
'post_routing' => [
49-
],
42+
// An array of middleware to register.
43+
[ /* ... */ ],
44+
Zend\Expressive\Container\ApplicationFactory::ROUTING_MIDDLEWARE,
45+
Zend\Expressive\Container\ApplicationFactory::DISPATCH_MIDDLEWARE,
46+
[ /* ... */ ],
5047
],
5148
```
5249

53-
Each item of each array must be an array itself, with the following structure:
50+
Each item of the array, other than the entries for routing and dispatch
51+
middleware, must be an array itself, with the following structure:
5452

5553
```php
5654
[
@@ -59,6 +57,7 @@ order to seed the `Application` instance:
5957
// optional:
6058
'path' => '/path/to/match',
6159
'error' => true,
60+
'priority' => 1, // Integer
6261
],
6362
```
6463

@@ -69,7 +68,16 @@ order to seed the `Application` instance:
6968
`error` key is present and boolean `true`, then the middleware will be
7069
registered as error middleware. (This is necessary due to the fact that the
7170
factory defines a callable wrapper around middleware to enable lazy-loading of
72-
middleware.)
71+
middleware.) The `priority` defaults to 1, and follows the semantics of
72+
[SplPriorityQueue](http://php.net/SplPriorityQueue): higher integer values
73+
indicate higher priority (will execute earlier), while lower/negative integer
74+
values indicate lower priority (will execute last). Default priority is 1; use
75+
granular priority values to specify the order in which middleware should be
76+
piped to the application.
77+
78+
You *can* specify keys for each middleware specification. These will be
79+
ignored by the factory, but can be useful when merging several configurations
80+
into one for the application.
7381

7482
- `routes` is used to define routed middleware. The value must be an array,
7583
consisting of arrays defining each middleware:

doc/book/cookbook/custom-404-page-handling.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -86,22 +86,25 @@ From there, you still need to register the middleware. This middleware is not
8686
routed, and thus needs to be piped to the application instance. You can do this
8787
via either configuration, or manually.
8888

89-
To do this via configuration, add an entry under the `post_routing` key of the
90-
`middleware_pipeline` configuration:
89+
To do this via configuration, add an entry under the `middleware_pipeline`
90+
configuration, after the dispatch middleware:
9191

9292
```php
9393
'middleware_pipeline' => [
94-
'pre_routing' => [
95-
[
96-
//...
94+
/* ... */
95+
'routing' => [
96+
'middleware' => [
97+
Zend\Expressive\Container\ApplicationFactory::ROUTING_MIDDLEWARE,
98+
Zend\Expressive\Helper\UrlHelperMiddleware::class,
99+
Zend\Expressive\Container\ApplicationFactory::DISPATCH_MIDDLEWARE,
97100
],
98-
101+
'priority' => 1,
99102
],
100-
'post_routing' => [
101-
[
102-
'middleware' => 'Application\NotFound',
103-
],
103+
[
104+
'middleware' => 'Application\NotFound',
105+
'priority' => -1,
104106
],
107+
/* ... */
105108
],
106109
```
107110

@@ -117,9 +120,7 @@ $app->pipe($container->get('Application\NotFound'));
117120

118121
This must be done *after*:
119122

120-
- calling `$app->pipeRoutingMiddleware()`, **OR**
121-
- calling any method that injects routed middleware (`get()`, `post()`,
122-
`route()`, etc.), **OR**
123+
- calling `$app->pipeDispatchMiddleware()`, **OR**
123124
- pulling the `Application` instance from the service container (assuming you
124125
used the `ApplicationFactory`).
125126

doc/book/cookbook/debug-toolbars.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,11 @@ return [
7474
],
7575
],
7676
'middleware_pipeline' => [
77-
'pre_routing' => [
78-
[
79-
'middleware' => [
80-
PhpDebugBarMiddleware::class,
81-
],
77+
[
78+
'middleware' => [
79+
PhpDebugBarMiddleware::class,
8280
],
81+
'priority' => 1000,
8382
],
8483
],
8584
];

doc/book/cookbook/route-specific-pipeline.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,24 +160,23 @@ When either of these approaches are used, the individual middleware listed
160160
This approach is essentially equivalent to creating a factory that returns a
161161
middleware pipeline.
162162

163-
## What about pre/post pipeline middleware?
163+
## What about pipeline middleware configuration?
164164

165-
What if you want to do this with pre- or post-pipeline middleware? The answer is
166-
that the syntax is exactly the same!
165+
What if you want to do this with your pipeline middleware configuration? The
166+
answer is that the syntax is exactly the same!
167167

168168
```php
169169
return [
170170
'middleware_pipeline' => [
171-
'pre_routing' => [
172-
[
173-
'path' => '/api',
174-
'middleware' => [
175-
'AuthenticationMiddleware',
176-
'AuthorizationMiddleware',
177-
'BodyParsingMiddleware',
178-
'ValidationMiddleware',
179-
],
171+
'api' => [
172+
'path' => '/api',
173+
'middleware' => [
174+
'AuthenticationMiddleware',
175+
'AuthorizationMiddleware',
176+
'BodyParsingMiddleware',
177+
'ValidationMiddleware',
180178
],
179+
'priority' => 100,
181180
],
182181
],
183182
];

0 commit comments

Comments
 (0)