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

Commit

Permalink
Merge pull request #406 from danizord/prepare-1-1
Browse files Browse the repository at this point in the history
Remove route result observers
  • Loading branch information
weierophinney committed Jan 9, 2017
2 parents e973162 + a362ab2 commit 9efe395
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 402 deletions.
203 changes: 0 additions & 203 deletions doc/book/features/router/result-observers.md

This file was deleted.

1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ pages:
- Introduction: features/router/intro.md
- 'Routing Interface': features/router/interface.md
- 'URI Generation': features/router/uri-generation.md
- 'Route Result Observers': features/router/result-observers.md
- 'Routing vs Piping': features/router/piping.md
- 'Using Aura': features/router/aura.md
- 'Using FastRoute': features/router/fast-route.md
Expand Down
103 changes: 2 additions & 101 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
/**
* Middleware application providing routing based on paths and HTTP methods.
*
* @todo For 1.1, remove the RouteResultSubjectInterface implementation, and
* all deprecated properties and methods.
* @method Router\Route get($path, $middleware, $name = null)
* @method Router\Route post($path, $middleware, $name = null)
* @method Router\Route put($path, $middleware, $name = null)
* @method Router\Route patch($path, $middleware, $name = null)
* @method Router\Route delete($path, $middleware, $name = null)
*/
class Application extends MiddlewarePipe implements Router\RouteResultSubjectInterface
class Application extends MiddlewarePipe
{
use ApplicationConfigInjectionTrait;
use MarshalMiddlewareTrait;
Expand Down Expand Up @@ -91,20 +89,6 @@ class Application extends MiddlewarePipe implements Router\RouteResultSubjectInt
*/
private $router;

/**
* @deprecated This property will be removed in v1.1.
* @var bool Flag indicating whether or not the route result observer
* middleware is registered in the middleware pipeline.
*/
private $routeResultObserverMiddlewareIsRegistered = false;

/**
* Observers to trigger once we have a route result.
*
* @var Router\RouteResultObserverInterface[]
*/
private $routeResultObservers = [];

/**
* List of all routes registered directly with the application.
*
Expand Down Expand Up @@ -201,8 +185,7 @@ public function __call($method, $args)
));
}

// @TODO: we can use variadic parameters when dependency is raised to PHP 5.6
return call_user_func_array([$this, 'route'], $args);
return $this->route(...$args);
}

/**
Expand All @@ -216,44 +199,6 @@ public function any($path, $middleware, $name = null)
return $this->route($path, $middleware, null, $name);
}

/**
* Attach a route result observer.
*
* @deprecated This method will be removed in v1.1.
* @param Router\RouteResultObserverInterface $observer
*/
public function attachRouteResultObserver(Router\RouteResultObserverInterface $observer)
{
$this->routeResultObservers[] = $observer;
}

/**
* Detach a route result observer.
*
* @deprecated This method will be removed in v1.1.
* @param Router\RouteResultObserverInterface $observer
*/
public function detachRouteResultObserver(Router\RouteResultObserverInterface $observer)
{
if (false === ($index = array_search($observer, $this->routeResultObservers, true))) {
return;
}
unset($this->routeResultObservers[$index]);
}

/**
* Notify all route result observers with the given route result.
*
* @deprecated This method will be removed in v1.1.
* @param Router\RouteResult
*/
public function notifyRouteResultObservers(Router\RouteResult $result)
{
foreach ($this->routeResultObservers as $observer) {
$observer->update($result);
}
}

/**
* Overload pipe() operation.
*
Expand Down Expand Up @@ -403,20 +348,6 @@ public function pipeDispatchMiddleware()
$this->pipe([$this, 'dispatchMiddleware']);
}

/**
* Register the route result observer middleware in the middleware pipeline.
*
* @deprecated This method will be removed in v1.1.
*/
public function pipeRouteResultObserverMiddleware()
{
if ($this->routeResultObserverMiddlewareIsRegistered) {
return;
}
$this->pipe([$this, 'routeResultObserverMiddleware']);
$this->routeResultObserverMiddlewareIsRegistered = true;
}

/**
* Middleware that routes the incoming request and delegates to the matched middleware.
*
Expand Down Expand Up @@ -502,36 +433,6 @@ public function dispatchMiddleware(ServerRequestInterface $request, ResponseInte
return $middleware($request, $response, $next);
}

/**
* Middleware for notifying route result observers.
*
* If the request has a route result, calls notifyRouteResultObservers().
*
* This middleware should be injected between the routing and dispatch
* middleware when creating your middleware pipeline.
*
* If you are using this, rewrite your observers as middleware that
* pulls the route result from the request instead.
*
* @deprecated This method will be removed in v1.1.
* @param ServerRequestInterface $request
* @param ResponseInterface $response
* @param callable $next
* @returns ResponseInterface
*/
public function routeResultObserverMiddleware(
ServerRequestInterface $request,
ResponseInterface $response,
callable $next
) {
$result = $request->getAttribute(Router\RouteResult::class, false);
if ($result) {
$this->notifyRouteResultObservers($result);
}

return $next($request, $response);
}

/**
* Add a route for the route middleware to match.
*
Expand Down
Loading

0 comments on commit 9efe395

Please sign in to comment.