當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Controller\Zone類代碼示例

本文整理匯總了PHP中Bolt\Controller\Zone的典型用法代碼示例。如果您正苦於以下問題:PHP Zone類的具體用法?PHP Zone怎麽用?PHP Zone使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Zone類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setFrameOptions

 /**
  * Set the 'X-Frame-Options' headers to prevent click-jacking, unless
  * specifically disabled. Backend only!
  *
  * @param Request  $request
  * @param Response $response
  */
 protected function setFrameOptions(Request $request, Response $response)
 {
     if (Zone::isBackend($request) && $this->app['config']->get('general/headers/x_frame_options')) {
         $response->headers->set('X-Frame-Options', 'SAMEORIGIN');
         $response->headers->set('Frame-Options', 'SAMEORIGIN');
     }
 }
開發者ID:zomars,項目名稱:bolt,代碼行數:14,代碼來源:GeneralListener.php

示例2: onKernelException

 /**
  * Render the not found page if on frontend and http exception
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     if (!$exception instanceof HttpExceptionInterface || Zone::isBackend($event->getRequest())) {
         return;
     }
     if ($exception->getStatusCode() !== Response::HTTP_NOT_FOUND) {
         return;
     }
     // If $notFoundPage is referencing a template, render it and be done.
     if ($this->render->hasTemplate($this->notFoundPage)) {
         try {
             $this->renderNotFound($event, $this->notFoundPage, []);
         } catch (TwigErrorLoader $e) {
             // Template not found, fall though to see if we can render a
             // record, failing that let the exception handler take over
         }
     }
     // Next try for referencing DB content.
     $content = $this->storage->getContent($this->notFoundPage, ['returnsingle' => true]);
     if (!$content instanceof Content || empty($content->id)) {
         return;
     }
     $template = $this->templateChooser->record($content);
     $this->renderNotFound($event, $template, $content->getTemplateContext());
 }
開發者ID:bolt,項目名稱:bolt,代碼行數:31,代碼來源:NotFoundListener.php

示例3: getGlobals

 public function getGlobals()
 {
     /** @var \Bolt\Config $config */
     $config = $this->app['config'];
     $configVal = $this->safe ? null : $config;
     /** @var \Bolt\Users $users */
     $users = $this->app['users'];
     /** @var \Bolt\Configuration\ResourceManager $resources */
     $resources = $this->app['resources'];
     $zone = null;
     /** @var RequestStack $requestStack */
     $requestStack = $this->app['request_stack'];
     if ($request = $requestStack->getCurrentRequest()) {
         $zone = Zone::get($request);
     }
     // User calls can cause exceptions that block the exception handler
     try {
         /** @deprecated Deprecated since 3.0, to be removed in 4.0. */
         $usersVal = $this->safe ? null : $users->getUsers();
         $usersCur = $users->getCurrentUser();
     } catch (\Exception $e) {
         $usersVal = null;
         $usersCur = null;
     }
     // Structured to allow PHPStorm's SymfonyPlugin to provide code completion
     return ['bolt_name' => $this->app['bolt_name'], 'bolt_version' => $this->app['bolt_version'], 'frontend' => $zone === Zone::FRONTEND, 'backend' => $zone === Zone::BACKEND, 'async' => $zone === Zone::ASYNC, 'paths' => $resources->getPaths(), 'theme' => $config->get('theme'), 'user' => $usersCur, 'users' => $usersVal, 'config' => $configVal];
 }
開發者ID:uk61,項目名稱:bolt,代碼行數:27,代碼來源:TwigExtension.php

示例4: setZone

 /**
  * Sets the request's zone if needed and returns it.
  *
  * @param Request $request
  *
  * @return string
  */
 public function setZone(Request $request)
 {
     if ($zone = Zone::get($request)) {
         return $zone;
     }
     $zone = $this->determineZone($request);
     Zone::set($request, $zone);
     return $zone;
 }
開發者ID:nectd,項目名稱:nectd-web,代碼行數:16,代碼來源:ZoneGuesser.php

示例5: testControllerZone

 /**
  * @covers \Bolt\Controller\Zone::get
  * @covers \Bolt\Controller\Zone::isBackend
  */
 public function testControllerZone()
 {
     $app = $this->getApp();
     $this->setRequest(Request::create('/bolt'));
     $request = $this->getRequest();
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $app['dispatcher']->dispatch(KernelEvents::REQUEST, new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
     $this->assertEquals('backend', Zone::get($request));
     $this->assertTrue(Zone::isBackend($request));
 }
開發者ID:zomars,項目名稱:bolt,代碼行數:14,代碼來源:GeneralTest.php

示例6: isEnabled

 /**
  * Check if snippets are allowed for this request.
  *
  * @param FilterResponseEvent $event
  */
 protected function isEnabled(FilterResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return false;
     }
     if (Zone::isFrontend($event->getRequest())) {
         return true;
     }
     return $event->getRequest()->attributes->get('allow_snippets', false);
 }
開發者ID:Johardmeier,項目名稱:bolt,代碼行數:15,代碼來源:SnippetListener.php

示例7: testControllerZone

 /**
  * @covers \Bolt\Controller\Zone::get
  * @covers \Bolt\Controller\Zone::isAsync
  */
 public function testControllerZone()
 {
     $app = $this->getApp();
     $this->allowLogin($app);
     $this->setRequest(Request::create('/async'));
     $request = $this->getRequest();
     $request->cookies->set($app['token.authentication.name'], 'dropbear');
     $kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
     $app['dispatcher']->dispatch(KernelEvents::REQUEST, new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
     $this->assertEquals('async', Zone::get($request));
     $this->assertTrue(Zone::isAsync($request));
 }
開發者ID:johndotcat,項目名稱:bolt,代碼行數:16,代碼來源:GeneralTest.php

示例8: onKernelException

 /**
  * Render the not found page if on frontend and http exception
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof HttpExceptionInterface || Zone::isBackend($event->getRequest())) {
         return;
     }
     $content = $this->storage->getContent($this->notFoundPage, ['returnsingle' => true]);
     if (!$content instanceof Content || empty($content->id)) {
         return;
     }
     $template = $this->templateChooser->record($content);
     $response = $this->render->render($template, $content->getTemplateContext());
     $event->setResponse($response);
 }
開發者ID:Johardmeier,項目名稱:bolt,代碼行數:18,代碼來源:NotFoundListener.php

示例9: onResponse

 /**
  * Callback for reponse event.
  *
  * @param FilterResponseEvent $event
  */
 public function onResponse(FilterResponseEvent $event)
 {
     if (!$event->isMasterRequest()) {
         return;
     }
     $response = $event->getResponse();
     if (strpos($response->headers->get('Content-Type'), 'text/html') === false) {
         return;
     }
     if (!Zone::isAsync($event->getRequest())) {
         $this->addSnippets();
     }
     $response->setContent($this->render->postProcess($response));
 }
開發者ID:AlexLStudio,項目名稱:bolt,代碼行數:19,代碼來源:SnippetListener.php

示例10: onKernelException

 /**
  * Handle errors thrown in the application.
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     $exception = $event->getException();
     // Log the error message
     $message = $exception->getMessage();
     $this->logger->critical($message, ['event' => 'exception', 'exception' => $exception]);
     if ($exception instanceof HttpExceptionInterface && !Zone::isBackend($event->getRequest())) {
         $message = "The page could not be found, and there is no 'notfound' set in 'config.yml'. Sorry about that.";
     }
     $context = ['class' => get_class($exception), 'message' => $message, 'code' => $exception->getCode(), 'trace' => $this->getSafeTrace($exception)];
     // Note: This uses the template from app/theme_defaults. Not app/view/twig.
     $response = $this->render->render('error.twig', ['context' => $context]);
     $event->setResponse($response);
 }
開發者ID:nectd,項目名稱:nectd-web,代碼行數:19,代碼來源:ExceptionListener.php

示例11: kernelException

 /**
  * Route for kernel exception handling.
  *
  * @param GetResponseForExceptionEvent $event
  *
  * @return Response
  */
 public function kernelException(GetResponseForExceptionEvent $event)
 {
     if ($this->app === null) {
         throw new \RuntimeException('Exception controller being used outside of request cycle.');
     }
     $exception = $event->getException();
     $message = $exception->getMessage();
     if ($exception instanceof HttpExceptionInterface && !Zone::isBackend($event->getRequest())) {
         $message = "The page could not be found, and there is no 'notfound' set in 'config.yml'. Sorry about that.";
     }
     $context = $this->getContextArray($exception);
     $context['type'] = 'general';
     $context['message'] = $message;
     $html = $this->app['twig']->render('@bolt/exception/general.twig', $context);
     $response = new Response($html, Response::HTTP_OK);
     $response->headers->set('X-Debug-Exception-Handled', time());
     return $response;
 }
開發者ID:bolt,項目名稱:bolt,代碼行數:25,代碼來源:Exception.php

示例12: getGlobals

 public function getGlobals()
 {
     /** @var \Bolt\Config $config */
     $config = $this->app['config'];
     /** @var \Bolt\Users $users */
     $users = $this->app['users'];
     /** @var \Bolt\Configuration\ResourceManager $resources */
     $resources = $this->app['resources'];
     $configVal = $this->safe ? null : $config;
     $usersVal = $this->safe ? null : $users->getUsers();
     $zone = null;
     /** @var RequestStack $requestStack */
     $requestStack = $this->app['request_stack'];
     if ($request = $requestStack->getCurrentRequest()) {
         $zone = Zone::get($request);
     }
     // Structured to allow PHPStorm's SymfonyPlugin to provide code completion
     return ['bolt_name' => $this->app['bolt_name'], 'bolt_version' => $this->app['bolt_version'], 'frontend' => $zone === Zone::FRONTEND, 'backend' => $zone === Zone::BACKEND, 'async' => $zone === Zone::ASYNC, 'paths' => $resources->getPaths(), 'theme' => $config->get('theme'), 'user' => $users->getCurrentUser(), 'users' => $usersVal, 'config' => $configVal];
 }
開發者ID:halechan,項目名稱:bolt,代碼行數:19,代碼來源:TwigExtension.php

示例13: onKernelException

 /**
  * Render the not found page if on frontend and http exception
  *
  * @param GetResponseForExceptionEvent $event
  */
 public function onKernelException(GetResponseForExceptionEvent $event)
 {
     if (!$event->getException() instanceof HttpExceptionInterface || Zone::isBackend($event->getRequest())) {
         return;
     }
     // If $notFoundPage is referencing a template, render it and be done.
     if ($this->render->hasTemplate($this->notFoundPage)) {
         $response = $this->render->render($this->notFoundPage);
         $event->setResponse($response);
         return;
     }
     // Next try for referencing DB content.
     $content = $this->storage->getContent($this->notFoundPage, ['returnsingle' => true]);
     if (!$content instanceof Content || empty($content->id)) {
         return;
     }
     $template = $this->templateChooser->record($content);
     $response = $this->render->render($template, [], $content->getTemplateContext());
     $event->setResponse($response);
 }
開發者ID:d-m-,項目名稱:bolt,代碼行數:25,代碼來源:NotFoundListener.php

示例14: processAsset

 /**
  * Process a single asset.
  *
  * @param FileAssetInterface $asset
  * @param Request            $request
  * @param Response           $response
  */
 protected function processAsset(FileAssetInterface $asset, Request $request, Response $response)
 {
     if ($asset->getZone() !== Zone::get($request)) {
         return;
     } elseif ($asset->isLate()) {
         if ($asset->getLocation() === null) {
             $location = Target::END_OF_BODY;
         } else {
             $location = $asset->getLocation();
         }
     } elseif ($asset->getLocation() !== null) {
         $location = $asset->getLocation();
     } else {
         $location = Target::END_OF_HEAD;
     }
     $this->injector->inject($asset, $location, $response);
 }
開發者ID:gandalf3,項目名稱:bolt,代碼行數:24,代碼來源:Queue.php

示例15: setGlobals

 /**
  * Get the parameters that will be used to update Bolt's registered Twig
  * globals.
  *
  * This is here as a transitory measure.
  *
  * @param bool $safe
  *
  * @return array
  */
 private function setGlobals($safe)
 {
     /** @var \Twig_Environment $twig */
     $twig = $safe ? $this->app['safe_twig'] : $this->app['twig'];
     /** @var \Bolt\Config $config */
     $config = $this->app['config'];
     $configVal = $safe ? null : $config;
     /** @var \Bolt\Users $users */
     $users = $this->app['users'];
     /** @var \Bolt\Configuration\ResourceManager $resources */
     $resources = $this->app['resources'];
     $zone = null;
     /** @var RequestStack $requestStack */
     $requestStack = $this->app['request_stack'];
     if ($request = $requestStack->getCurrentRequest()) {
         $zone = Zone::get($request);
     }
     // User calls can cause exceptions that block the exception handler
     try {
         /** @deprecated Deprecated since 3.0, to be removed in 4.0. */
         $usersVal = $safe ? null : $users->getUsers();
         $usersCur = $users->getCurrentUser();
     } catch (\Exception $e) {
         $usersVal = null;
         $usersCur = null;
     }
     $twig->addGlobal('bolt_name', Bolt\Version::name());
     $twig->addGlobal('bolt_version', Bolt\Version::VERSION);
     $twig->addGlobal('bolt_stable', Bolt\Version::isStable());
     $twig->addGlobal('frontend', $zone === Zone::FRONTEND);
     $twig->addGlobal('backend', $zone === Zone::BACKEND);
     $twig->addGlobal('async', $zone === Zone::ASYNC);
     $twig->addGlobal('paths', $resources->getPaths());
     $twig->addGlobal('theme', $config->get('theme'));
     $twig->addGlobal('user', $usersCur);
     $twig->addGlobal('users', $usersVal);
     $twig->addGlobal('config', $configVal);
 }
開發者ID:nbehier,項目名稱:bolt,代碼行數:48,代碼來源:BootInitListener.php


注:本文中的Bolt\Controller\Zone類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。