本文整理汇总了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');
}
}
示例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());
}
示例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];
}
示例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;
}
示例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));
}
示例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);
}
示例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));
}
示例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);
}
示例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));
}
示例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);
}
示例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;
}
示例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];
}
示例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);
}
示例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);
}
示例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);
}