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

Commit

Permalink
Merge branch 'hotfix/route-result-observer'
Browse files Browse the repository at this point in the history
Close #206
  • Loading branch information
weierophinney committed Dec 3, 2015
2 parents 2ca2f21 + 394c87a commit e161d2e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 16 deletions.
19 changes: 10 additions & 9 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@ Third release candidate.
array **must** be callables, service names resolving to callable middleware,
or fully qualified class names that can be instantiated without arguments, and
which result in invokable middleware.
- [#200](https://github.com/zendframework/zend-expressive/pull/200) adds a new
interface, `Zend\Expressive\Router\RouteResultObserverInterface` (since moved
to the zend-expressive-router package). `Zend\Expressive\Application` now
also defines two methods, `attachRouteResultObserver()` and
`detachRouteResultObserver()`, which accept instances of the interface. During
`routeMiddleware()`, all observers are updated immediately following the call
to `RouterInterface::match()` with the `RouteResult` instance. This feature
enables the ability to notify objects of the calculated `RouteResult` without
needing to inject middleware into the system.
- [#200](https://github.com/zendframework/zend-expressive/pull/200) and
[#206](https://github.com/zendframework/zend-expressive/pull/206) add a new
interface, `Zend\Expressive\RouteResultObserverInterface`.
`Zend\Expressive\Application` now also defines two methods,
`attachRouteResultObserver()` and `detachRouteResultObserver()`, which accept
instances of the interface. During `routeMiddleware()`, all observers are
updated immediately following the call to `RouterInterface::match()` with the
`RouteResult` instance. This feature enables the ability to notify objects of
the calculated `RouteResult` without needing to inject middleware into the
system.
- [#81](https://github.com/zendframework/zend-expressive/pull/81) adds a
cookbook entry for creating 404 handlers.

Expand Down
6 changes: 4 additions & 2 deletions doc/book/router/result-observers.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ you to notify such utilities of the results of matching.
Route result observers must implement the `RouteResultObserverInterface`:

```php
namespace Zend\Expressive\Router;
namespace Zend\Expressive;

use Zend\Expressive\Router\RouteResult;

interface RouteResultObserverInterface
{
Expand Down Expand Up @@ -59,7 +61,7 @@ when invoked, generate a URI.
```php
use Zend\Expressive\Router\RouterInterface;
use Zend\Expressive\Router\RouteResult;
use Zend\Expressive\Router\RouteResultObserverInterface;
use Zend\Expressive\RouteResultObserverInterface;

class UriGenerator implements RouteResultObserverInterface
{
Expand Down
8 changes: 4 additions & 4 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,19 @@ public function any($path, $middleware, $name = null)
/**
* Attach a route result observer.
*
* @param Router\RouteResultObserverInterface $observer
* @param RouteResultObserverInterface $observer
*/
public function attachRouteResultObserver(Router\RouteResultObserverInterface $observer)
public function attachRouteResultObserver(RouteResultObserverInterface $observer)
{
$this->routeResultObservers[] = $observer;
}

/**
* Detach a route result observer.
*
* @param Router\RouteResultObserverInterface $observer
* @param RouteResultObserverInterface $observer
*/
public function detachRouteResultObserver(Router\RouteResultObserverInterface $observer)
public function detachRouteResultObserver(RouteResultObserverInterface $observer)
{
if (false === ($index = array_search($observer, $this->routeResultObservers, true))) {
return;
Expand Down
22 changes: 22 additions & 0 deletions src/RouteResultObserverInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @see https://github.com/zendframework/zend-expressive for the canonical source repository
* @copyright Copyright (c) 2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-expressive/blob/master/LICENSE.md New BSD License
*/

namespace Zend\Expressive;

use Zend\Expressive\Router\RouteResult;

interface RouteResultObserverInterface
{
/**
* Observe a route result.
*
* @param RouteResult $result
*/
public function update(RouteResult $result);
}
2 changes: 1 addition & 1 deletion test/RouteMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Zend\Diactoros\ServerRequest;
use Zend\Expressive\Application;
use Zend\Expressive\Router\RouteResult;
use Zend\Expressive\Router\RouteResultObserverInterface;
use Zend\Expressive\RouteResultObserverInterface;
use Zend\Expressive\Router\RouterInterface;

class RouteMiddlewareTest extends TestCase
Expand Down

0 comments on commit e161d2e

Please sign in to comment.