Symfony\Component\HttpKernel\HttpKernelInterface::handle PHP Method

handle() public method

When $catch is true, the implementation must catch all exceptions and do its best to convert them to a Response instance.
public handle ( Request $request, integer $type = self::MASTER_REQUEST, boolean $catch = true ) : Response
$request Symfony\Component\HttpFoundation\Request A Request instance
$type integer The type of the request (one of HttpKernelInterface::MASTER_REQUEST or HttpKernelInterface::SUB_REQUEST)
$catch boolean Whether to catch exceptions or not
return Response A Response instance
    function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true);

Same methods

HttpKernelInterface::handle ( Request $request, integer $type = self::MASTER_REQUEST, boolean $catch = true ) : Response

Usage Example

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     $config = $this->configFactory->get('shield.settings');
     $allow_cli = $config->get('allow_cli');
     $user = $config->get('user');
     $pass = $config->get('pass');
     if (empty($user) || PHP_SAPI === 'cli' && $allow_cli) {
         // If username is empty, then authentication is disabled,
         // or if request is coming from a cli and it is allowed,
         // then proceed with response without shield authentication.
         return $this->httpKernel->handle($request, $type, $catch);
     } else {
         if ($request->server->has('PHP_AUTH_USER') && $request->server->has('PHP_AUTH_PW')) {
             $input_user = $request->server->get('PHP_AUTH_USER');
             $input_pass = $request->server->get('PHP_AUTH_PW');
         } elseif ($request->server->has('HTTP_AUTHORIZATION')) {
             list($input_user, $input_pass) = explode(':', base64_decode(substr($request->server->get('HTTP_AUTHORIZATION'), 6)), 2);
         } elseif ($request->server->has('REDIRECT_HTTP_AUTHORIZATION')) {
             list($input_user, $input_pass) = explode(':', base64_decode(substr($request->server->get('REDIRECT_HTTP_AUTHORIZATION'), 6)), 2);
         }
         if (isset($input_user) && $input_user === $user && Crypt::hashEquals($pass, $input_pass)) {
             return $this->httpKernel->handle($request, $type, $catch);
         }
     }
     $response = new Response();
     $response->headers->add(['WWW-Authenticate' => 'Basic realm="' . strtr($config->get('print'), ['[user]' => $user, '[pass]' => $pass]) . '"']);
     $response->setStatusCode(401);
     return $response;
 }
All Usage Examples Of Symfony\Component\HttpKernel\HttpKernelInterface::handle
HttpKernelInterface