This repository has been archived by the owner on Jan 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/decorator-deprecation' into dev-2.0.0
Forward port #70 to dev-2.0.0 Conflicts: doc/book/migration/to-v2.md src/FinalHandler.php test/FinalHandlerTest.php test/MiddlewarePipeTest.php
- Loading branch information
Showing
11 changed files
with
363 additions
and
2 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
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
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,52 @@ | ||
<?php | ||
/** | ||
* @link https://github.com/zendframework/zend-stratigility for the canonical source repository | ||
* @copyright Copyright (c) 2016 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Stratigility\Middleware; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Zend\Stratigility\MiddlewareInterface; | ||
|
||
/** | ||
* Inject attributes containing the original request, response, and URI instances. | ||
* | ||
* This middleware will add request attributes as follows: | ||
* | ||
* - "originalRequest", representing the request provided to this middleware. | ||
* - "originalResponse", representing the response provided to this middleware. | ||
* - "originalUri", representing the URI composed by the request provided to | ||
* this middleware. | ||
* | ||
* These can then be reference later, for tasks such as: | ||
* | ||
* - Determining the base path when generating a URI (as layers may receive | ||
* URIs stripping path segments). | ||
* - Determining if changes to the response have occurred. | ||
* - Providing prototypes for factories. | ||
*/ | ||
class OriginalMessages implements MiddlewareInterface | ||
{ | ||
/** | ||
* @param ServerRequestInterface $request | ||
* @param ResponseInterface $response | ||
* @param null|callable $next | ||
* @return ResponseInterface | ||
*/ | ||
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null) | ||
{ | ||
if (! $next) { | ||
return $response; | ||
} | ||
|
||
$request = $request | ||
->withAttribute('originalUri', $request->getUri()) | ||
->withAttribute('originalRequest', $request) | ||
->withAttribute('originalResponse', $response); | ||
|
||
return $next($request, $response); | ||
} | ||
} |
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
Oops, something went wrong.