terminate example


  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();

    try {
      
/** * @param Request $request * * @return Response */
    protected function doRequest(object $request)
    {
        $response = $this->kernel->handle($request, HttpKernelInterface::MAIN_REQUEST, $this->catchExceptions);

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

        return $response;
    }

    /** * @param Request $request * * @return string */
    protected function getScript(object $request)
    {

        // Do not call any listeners in case of a cache hit.         // This ensures identical behavior as if you had a separate         // reverse caching proxy such as Varnish and the like.         if ($this->options['terminate_on_cache_hit']) {
            trigger_deprecation('symfony/http-kernel', '6.2', 'Setting "terminate_on_cache_hit" to "true" is deprecated and will be changed to "false" in Symfony 7.0.');
        } elseif (\in_array('fresh', $this->traces[$this->getTraceKey($request)] ?? [], true)) {
            return;
        }

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

    /** * Forwards the Request to the backend without storing the Response in the cache. * * @param bool $catch Whether to process exceptions */
    protected function pass(Request $request, bool $catch = false): Response
    {
        $this->record($request, 'pass');

        
/** * @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;
        }

        


            $this->executeCommand("DATA\r\n", [354]);
            try {
                foreach (AbstractStream::replace("\r\n.", "\r\n..", $message->toIterable()) as $chunk) {
                    $this->stream->write($chunk, false);
                }
                $this->stream->flush();
            } catch (TransportExceptionInterface $e) {
                throw $e;
            } catch (\Exception $e) {
                $this->stream->terminate();
                $this->started = false;
                $this->getLogger()->debug(sprintf('Email transport "%s" stopped', __CLASS__));
                throw $e;
            }
            $this->mtaResult = $this->executeCommand("\r\n.\r\n", [250]);
            $message->appendDebug($this->stream->getDebug());
            $this->lastMessageTime = microtime(true);
        } catch (TransportExceptionInterface $e) {
            $e->appendDebug($this->stream->getDebug());
            $this->lastMessageTime = 0;
            throw $e;
        }


$request = Request::createFromGlobals();

@set_time_limit(0);
@ignore_user_abort(true);

$response = $kernel->handle($request);

$response->send();

$kernel->terminate($request$response);

        // Do not call any listeners in case of a cache hit.         // This ensures identical behavior as if you had a separate         // reverse caching proxy such as Varnish and the like.         if ($this->options['terminate_on_cache_hit']) {
            trigger_deprecation('symfony/http-kernel', '6.2', 'Setting "terminate_on_cache_hit" to "true" is deprecated and will be changed to "false" in Symfony 7.0.');
        } elseif (\in_array('fresh', $this->traces[$this->getTraceKey($request)] ?? [], true)) {
            return;
        }

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

    /** * Forwards the Request to the backend without storing the Response in the cache. * * @param bool $catch Whether to process exceptions */
    protected function pass(Request $request, bool $catch = false): Response
    {
        $this->record($request, 'pass');

        
private readonly HttpKernelInterface $kernel,
        private readonly Request $request,
    ) {
    }

    public function run(): int
    {
        $response = $this->kernel->handle($this->request);
        $response->send();

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

        return 0;
    }
}
if (drupal_valid_test_ua()) {
  gc_collect_cycles();
  gc_disable();
}

$kernel = new UpdateKernel('prod', $autoloader, FALSE);
$request = Request::createFromGlobals();

$response = $kernel->handle($request);
$response->send();

$kernel->terminate($request$response);
 finally {
            restore_error_handler();
        }
    }

    public function terminate(): void
    {
        if (null !== $this->stream) {
            fclose($this->stream);
        }

        parent::terminate();
    }

    protected function getReadConnectionDescription(): string
    {
        return $this->url;
    }
}
foreach ($_SERVER as &$value) {
  $value = str_replace('core/modules/system/tests/https.php', 'index.php', $value);
  $value = str_replace('http://', 'https://', $value);
}

$kernel = new TestKernel('testing', $autoloader, TRUE);

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();

$kernel->terminate($request$response);

            $this->httpKernel = $httpKernel;
        }

        public function handle(Request $request, int $type = self::MAIN_REQUEST, bool $catch = true): Response
        {
            return $this->httpKernel->handle($request$type$catch)->getResponse();
        }

        public function terminate(Request $request, Response $response): void
        {
            $this->httpKernel->terminate($request$response);
        }
    };
};
$this->out = &$pipes[1];
    }

    public function terminate(): void
    {
        if (null !== $this->stream) {
            fclose($this->in);
            fclose($this->out);
            proc_close($this->stream);
        }

        parent::terminate();
    }

    protected function getReadConnectionDescription(): string
    {
        return 'process '.$this->command;
    }
}
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;

$autoloader = require_once 'autoload.php';

$kernel = new DrupalKernel('prod', $autoloader);

$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();

$kernel->terminate($request$response);
$kernel = $this->getKernel([][$fooBundle$barBundle]);
        $kernel->boot();
    }

    public function testTerminateReturnsSilentlyIfKernelIsNotBooted()
    {
        $kernel = $this->getKernel(['getHttpKernel']);
        $kernel->expects($this->never())
            ->method('getHttpKernel');

        $kernel->terminate(Request::create('/')new Response());
    }

    public function testTerminateDelegatesTerminationOnlyForTerminableInterface()
    {
        // does not implement TerminableInterface         $httpKernel = new TestKernel();

        $kernel = $this->getKernel(['getHttpKernel']);
        $kernel->expects($this->once())
            ->method('getHttpKernel')
            ->willReturn($httpKernel);

        
Home | Imprint | This part of the site doesn't use cookies.