Skip to content
Snippets Groups Projects
Kernel.php 1.2 KiB
Newer Older
Maxime Veber's avatar
Maxime Veber committed
<?php
/**
 * This file is a part of SymfonySecurity package.
 *
 * (c) Nekland <dev@nekland.fr>
 *
 * For the full license, take a look to the LICENSE file
 * on the root directory of this project
 */

namespace BiiG\SecurityTest;


use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\KernelEvents;

class Kernel implements HttpKernelInterface
{
    private $dispatcher;

    private $run;

    public function __construct(EventDispatcher $dispatcher, \Closure $run)
    {
        $this->dispatcher = $dispatcher;
        $this->run = $run;
    }

    public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
    {
        $this->dispatcher->dispatch(KernelEvents::REQUEST, new GetResponseEvent($this, $request, $type));

        // Some work
        $run = $this->run;
Maxime Veber's avatar
Maxime Veber committed
        $response = $run();
Maxime Veber's avatar
Maxime Veber committed

        $this->dispatcher->dispatch(KernelEvents::FINISH_REQUEST, new FinishRequestEvent($this, $request, $type));
Maxime Veber's avatar
Maxime Veber committed

        return $response;
Maxime Veber's avatar
Maxime Veber committed
    }
}