Skip to content

Instantly share code, notes, and snippets.

Created October 19, 2014 21:24
Show Gist options
  • Select an option

  • Save anonymous/f276054e9866456021bc to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/f276054e9866456021bc to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Oct 19, 2014.
    23 changes: 23 additions & 0 deletions MyMiddleware.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <?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
    )
    }
    }
    20 changes: 20 additions & 0 deletions MyRequestDecorator.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    <?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...
    }