当前位置: 首页>>代码示例>>PHP>>正文


PHP HttpKernelInterface::handle方法代码示例

本文整理汇总了PHP中Symfony\Component\HttpKernel\HttpKernelInterface::handle方法的典型用法代码示例。如果您正苦于以下问题:PHP HttpKernelInterface::handle方法的具体用法?PHP HttpKernelInterface::handle怎么用?PHP HttpKernelInterface::handle使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\HttpKernel\HttpKernelInterface的用法示例。


在下文中一共展示了HttpKernelInterface::handle方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: handle

 /**
  * {@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;
 }
开发者ID:eigentor,项目名称:tommiblog,代码行数:32,代码来源:ShieldMiddleware.php

示例2: onRequest

 /**
  * Handle a request
  *
  * @param ReactRequest  $request
  * @param ReactResponse $response
  */
 public function onRequest(ReactRequest $request, ReactResponse $response)
 {
     $content = '';
     $headers = $request->getHeaders();
     $contentLength = isset($headers['Content-Length']) ? (int) $headers['Content-Length'] : 0;
     $request->on('data', function ($data) use($request, $response, &$content, $contentLength) {
         // Read data (may be empty for GET request)
         $content .= $data;
         // Handle request after receive
         if (strlen($content) >= $contentLength) {
             $symfonyRequest = static::mapRequest($request, $content);
             try {
                 // Execute
                 $symfonyResponse = $this->application->handle($symfonyRequest);
             } catch (\Throwable $t) {
                 // Executed only in PHP 7, will not match in PHP 5.x
                 $this->fatalError($response, $t);
                 return;
             } catch (\Exception $e) {
                 // Executed only in PHP 5.x, will not be reached in PHP 7
                 $this->fatalError($response, $e);
                 return;
             }
             static::mapResponse($response, $symfonyResponse);
             if ($this->application instanceof SymfonyHttpKernel\TerminableInterface) {
                 $this->application->terminate($symfonyRequest, $symfonyResponse);
             }
         }
     });
 }
开发者ID:M6Web,项目名称:PhpProcessManagerBundle,代码行数:36,代码来源:HttpKernel.php

示例3: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     // always set the session onto the request object.
     $request->setSession($this->session);
     // we only need to manage the session for the master request.
     // subrequests will have the session available anyways, but we will
     // be closing and setting the cookie for the master request only.
     if ($type !== HttpKernelInterface::MASTER_REQUEST) {
         return $this->kernel->handle($request, $type, $catch);
     }
     // the session may have been manually started before the middleware is
     // invoked - in this case, we cross our fingers and hope the session has
     // properly initialised itself
     if (!$this->session->isStarted()) {
         $this->initSession($request);
     }
     $response = $this->kernel->handle($request, $type, $catch);
     // if the session has started, save it and attach the session cookie. if
     // the session has not started, there is nothing to save and there is no
     // point in attaching a cookie to persist it.
     if ($this->session->isStarted()) {
         $this->closeSession($request, $response);
     }
     return $response;
 }
开发者ID:autarky,项目名称:framework,代码行数:28,代码来源:SessionMiddleware.php

示例4: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     if (\Drupal::state()->get('error_service_test.break_bare_html_renderer')) {
         // Let the bedlam begin.
         // 1) Force a container rebuild.
         /** @var \Drupal\Core\DrupalKernelInterface $kernel */
         $kernel = \Drupal::service('kernel');
         $kernel->rebuildContainer();
         // 2) Fetch the in-situ container builder.
         $container = ErrorServiceTestServiceProvider::$containerBuilder;
         // Ensure the compiler pass worked.
         if (!$container) {
             throw new \Exception('Oh oh, monkeys stole the ServiceProvider.');
         }
         // Stop the theme manager from being found - and triggering error
         // maintenance mode.
         $container->removeDefinition('theme.manager');
         // Mash. Mash. Mash.
         \Drupal::setContainer($container);
         throw new \Exception('Oh oh, bananas in the instruments.');
     }
     if (\Drupal::state()->get('error_service_test.break_logger')) {
         throw new \Exception('Deforestation');
     }
     return $this->app->handle($request, $type, $catch);
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:29,代码来源:MonkeysInTheControlRoom.php

示例5: redirect

 protected function redirect($params, $event)
 {
     $subRequest = $this->request->duplicate(array(), null, $params);
     $response = $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
     $event->setResponse($response);
     $event->stopPropagation();
 }
开发者ID:ngodfraind,项目名称:SocialmediaBundle,代码行数:7,代码来源:ResourceActionsListener.php

示例6: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     // TODO Probably we can move here the database log start and the initial
     //   read of memory usage.
     Timer::start('devel_page');
     return $this->httpKernel->handle($request, $type, $catch);
 }
开发者ID:KenG01,项目名称:Achieve-D8,代码行数:10,代码来源:DevelMiddleware.php

示例7: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     $route = $request->getPathInfo();
     // We have an active login
     if ($this->sessionAuth->check()) {
         switch ($route) {
             case '/login':
                 $returnUri = $request->query->get('uri', $request->attributes->get('stack.url_map.prefix', '/'));
                 return new RedirectResponse($returnUri);
                 break;
             case '/logout':
                 $this->sessionAuth->logout();
                 return new RedirectResponse($request->attributes->get('stack.url_map.prefix', '/'));
                 break;
             default:
                 $caller = $this->sessionAuth->getCurrentCaller();
                 $request->attributes->set('stack.authn.token', $caller->getLoginToken());
                 if ($this->options['delegateCaller']) {
                     $request->attributes->set('stack.authn.caller', $caller);
                 }
                 break;
         }
     } elseif ($route !== '/login') {
         $routePrefix = $request->attributes->get('stack.url_map.prefix', '');
         $fullRoute = $request->server->get('PATH_INFO', '/');
         return new RedirectResponse(sprintf('%s/%s?uri=%s', $routePrefix, $this->options['loginUri'], $fullRoute));
     }
     return $this->app->handle($request, $type, $catch);
 }
开发者ID:guardianphp,项目名称:stack-integration,代码行数:32,代码来源:Authentication.php

示例8: getAuditFields

 /**
  * @return string Json encoded
  */
 protected function getAuditFields()
 {
     $path = ['_controller' => 'OroDataAuditBundle:Api/Rest/Audit:getFields'];
     $subRequest = $this->request->duplicate(['_format' => 'json'], null, $path);
     $response = $this->httpKernel->handle($subRequest, HttpKernelInterface::MASTER_REQUEST);
     return $response->getContent();
 }
开发者ID:Maksold,项目名称:platform,代码行数:10,代码来源:SegmentWidgetOptionsListener.php

示例9: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     if ($request->headers->has('Accept')) {
         $request->setRequestFormat($request->getFormat($request->headers->get('Accept')));
     }
     return $this->httpKernel->handle($request, $type, $catch);
 }
开发者ID:Jbartsch,项目名称:travelbruh-api,代码行数:10,代码来源:FormatSetter.php

示例10: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = TRUE)
 {
     if ($request->getClientIp() == '127.0.0.10') {
         return new Response(t('Bye!'), 403);
     }
     return $this->httpKernel->handle($request, $type, $catch);
 }
开发者ID:chi-teck,项目名称:drupal-code-generator,代码行数:10,代码来源:_middleware.php

示例11: handle

 /**
  * @param Request $request
  * @param int     $type
  * @param bool    $catch
  *
  * @return Response
  * @throws \Exception
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     if ($type === HttpKernelInterface::SUB_REQUEST) {
         return $this->app->handle($request, $type, $catch);
     }
     $parameters = $this->config->get('cookie_parameters');
     if (!isset($parameters[$this->config->get('current_locale')])) {
         throw new \Exception(sprintf('Domain %s not available', $this->config->get('current_locale')));
     }
     $cookieParams = $parameters[$this->config->get('current_locale')];
     $this->config->set('current_cookie_domain', $cookieParams['domain']);
     if (HttpKernelInterface::MASTER_REQUEST !== $type) {
         return $this->app->handle($request, $type, $catch);
     }
     $session = new Session();
     $request->setSession($session);
     $cookies = $request->cookies;
     if ($cookies->has($session->getName())) {
         $session->setId($cookies->get($session->getName()));
     } else {
         //starts the session if no session exists
         $session->start();
         $session->migrate(false);
     }
     $session->start();
     $response = $this->app->handle($request, $type, $catch);
     if ($session && $session->isStarted()) {
         $session->save();
         $params = array_merge(session_get_cookie_params(), $cookieParams);
         $cookie = new Cookie($session->getName(), $session->getId(), 0 === $params['lifetime'] ? 0 : $request->server->get('REQUEST_TIME') + $params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']);
         $response->headers->setCookie($cookie);
     }
     return $response;
 }
开发者ID:evaneos,项目名称:pyrite,代码行数:42,代码来源:SessionMiddleware.php

示例12: handle

 /**
  * Handle a request.
  *
  * @param SyfmonyRequest $request
  * @param int $type
  * @param bool $catch
  * @return Response
  */
 public function handle(SyfmonyRequest $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     $request = Request::createFromBase($request);
     $request->enableHttpMethodParameterOverride();
     $this->app->bind('request', $request);
     return $this->httpKernel->handle($request);
 }
开发者ID:codeception,项目名称:base,代码行数:15,代码来源:Laravel5.php

示例13: handle

 /**
  * {@inheritdoc}
  */
 public function handle(Request $request, $type = self::MASTER_REQUEST, $catch = true)
 {
     try {
         $response = $this->app->handle($request, $type, $catch);
         if ($response instanceof Response) {
             return $response;
         }
     } catch (DatabaseConnectionException $e) {
         $message = $e->getMessage();
     } catch (\Exception $e) {
         error_log($e);
         if (MAUTIC_ENV == 'dev') {
             $message = "<pre>{$e->getMessage()} - in file {$e->getFile()} - at line {$e->getLine()}</pre>";
             $submessage = "<pre>{$e->getTraceAsString()}</pre>";
         } else {
             $message = 'The site is currently offline due to encountering an error. If the problem persists, please contact the system administrator.';
             $submessage = 'System administrators, check server logs for errors.';
         }
     }
     if (isset($message)) {
         define('MAUTIC_OFFLINE', 1);
         ob_start();
         include MAUTIC_ROOT_DIR . '/offline.php';
         $content = ob_get_clean();
         return new Response($content, 500);
     }
 }
开发者ID:Yame-,项目名称:mautic,代码行数:30,代码来源:CatchExceptionMiddleware.php

示例14: onRequest

 /**
  * Handle a request using a HttpKernelInterface implementing application.
  *
  * @param \React\Http\Request $request
  * @param \React\Http\Response $response
  */
 public function onRequest(ReactRequest $request, ReactResponse $response)
 {
     if (null === $this->application) {
         return;
     }
     $content = '';
     $headers = $request->getHeaders();
     $contentLength = isset($headers['Content-Length']) ? (int) $headers['Content-Length'] : 0;
     $request->on('data', function ($data) use($request, $response, &$content, $contentLength) {
         // read data (may be empty for GET request)
         $content .= $data;
         // handle request after receive
         if (strlen($content) >= $contentLength) {
             $syRequest = self::mapRequest($request, $content);
             try {
                 $syResponse = $this->application->handle($syRequest);
             } catch (\Exception $exception) {
                 $response->writeHead(500);
                 // internal server error
                 $response->end();
                 return;
             }
             self::mapResponse($response, $syResponse);
             if ($this->application instanceof TerminableInterface) {
                 $this->application->terminate($syRequest, $syResponse);
             }
         }
     });
 }
开发者ID:nghenglim,项目名称:php-pm-httpkernel,代码行数:35,代码来源:HttpKernel.php

示例15: handle

 /**
  * Handle a given request and return the response.
  *
  * @param  \Symfony\Component\HttpFoundation\Request  $request
  * @param  int  $type
  * @param  bool  $catch
  * @return \Symfony\Component\HttpFoundation\Response
  * @throws \Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException
  */
 public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
 {
     // Our middleware needs to ensure that Laravel is booted before we
     // can do anything. This gives us access to all the booted
     // service providers and other container bindings.
     $this->container->boot();
     if ($request instanceof InternalRequest || $this->auth->user()) {
         return $this->app->handle($request, $type, $catch);
     }
     // If a collection exists for the request and we can match a route
     // from the request then we'll check to see if the route is
     // protected and, if it is, we'll attempt to authenticate.
     if ($this->router->requestTargettingApi($request) && ($collection = $this->getApiRouteCollection($request))) {
         try {
             $route = $this->controllerReviser->revise($collection->match($request));
             if ($this->routeIsProtected($route)) {
                 return $this->authenticate($request, $route) ?: $this->app->handle($request, $type, $catch);
             }
         } catch (HttpExceptionInterface $exception) {
             // If we catch an HTTP exception then we'll simply let
             // the wrapping kernel do its thing.
         }
     }
     return $this->app->handle($request, $type, $catch);
 }
开发者ID:iwillhappy1314,项目名称:laravel-admin,代码行数:34,代码来源:Authentication.php


注:本文中的Symfony\Component\HttpKernel\HttpKernelInterface::handle方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。