Created
October 19, 2014 21:24
-
-
Save anonymous/f276054e9866456021bc to your computer and use it in GitHub Desktop.
Implementing decorators in middlewares to work with immutable Requests
This file contains hidden or 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
<?php | |
namespace Acme; | |
use Symfony\Component\HttpKernel\HTTPKernelInterface; | |
use Psr\Http\Message\Request; | |
class MyMiddleware implements HTTPKernelInterface { | |
private $kernel; | |
public function __construct(HTTPKernelInterface $kernel) | |
{ | |
$this->kernel = $kernel; | |
} | |
public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true) | |
{ | |
return $this->kernel->handle( | |
new MyRequestDecorator($request), | |
$type, | |
$catch | |
) | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace Acme; | |
use Psr\Http\Message\Request; | |
class MyRequestDecorator implements Request { | |
private $request; | |
public function __construct(Request $request) | |
{ | |
$this->request = $request; | |
} | |
public function getQueryParams() | |
{ | |
return ['foo' => 'bar']; | |
} | |
// Act as a proxy for all other methods... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment