getHttpKernel example



    /** * @return void */
    public function terminate(Request $request, Response $response)
    {
        if (false === $this->booted) {
            return;
        }

        if ($this->getHttpKernel() instanceof TerminableInterface) {
            $this->getHttpKernel()->terminate($request$response);
        }
    }

    /** * @return void */
    public function shutdown()
    {
        if (false === $this->booted) {
            return;
        }

  public function terminate(Request $request, Response $response) {
    // Only run terminate() when essential services have been set up properly     // by preHandle() before.     if (FALSE === $this->prepared) {
      return;
    }

    if ($this->getHttpKernel() instanceof TerminableInterface) {
      $this->getHttpKernel()->terminate($request$response);
    }
  }

  /** * {@inheritdoc} */
  public function handle(Request $request$type = self::MAIN_REQUEST, $catch = TRUE): Response {
    // Ensure sane PHP environment variables.     static::bootEnvironment();

    
class HttpKernelTest extends TestCase
{
    /** * Catch exceptions: true * Throwable type: RuntimeException * Listener: false. */
    public function testHandleWhenControllerThrowsAnExceptionAndCatchIsTrue()
    {
        $this->expectException(\RuntimeException::class);
        $kernel = $this->getHttpKernel(new EventDispatcher()static fn () => throw new \RuntimeException());

        $kernel->handle(new Request(), HttpKernelInterface::MAIN_REQUEST, true);
    }

    public function testRequestStackIsNotBrokenWhenControllerThrowsAnExceptionAndCatchIsTrue()
    {
        $requestStack = new RequestStack();
        $kernel = $this->getHttpKernel(new EventDispatcher()static fn () => throw new \RuntimeException()$requestStack);

        try {
            $kernel->handle(new Request(), HttpKernelInterface::MASTER_REQUEST, true);
        }


    /** * @return void */
    public function terminate(Request $request, Response $response)
    {
        if (false === $this->booted) {
            return;
        }

        if ($this->getHttpKernel() instanceof TerminableInterface) {
            $this->getHttpKernel()->terminate($request$response);
        }
    }

    /** * @return void */
    public function shutdown()
    {
        if (false === $this->booted) {
            return;
        }
use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
use Symfony\Component\HttpKernel\Debug\TraceableEventDispatcher;
use Symfony\Component\HttpKernel\HttpKernel;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Contracts\EventDispatcher\Event;

class TraceableEventDispatcherTest extends TestCase
{
    public function testStopwatchSections()
    {
        $dispatcher = new TraceableEventDispatcher(new EventDispatcher()$stopwatch = new Stopwatch());
        $kernel = $this->getHttpKernel($dispatcher);
        $request = Request::create('/');
        $response = $kernel->handle($request);
        $kernel->terminate($request$response);

        $events = $stopwatch->getSectionEvents($request->attributes->get('_stopwatch_token'));
        $this->assertEquals([
            '__section__',
            'kernel.request',
            'kernel.controller',
            'kernel.controller_arguments',
            'controller',
            
Home | Imprint | This part of the site doesn't use cookies.