本文整理汇总了PHP中Bolt\Controller\Zone类的典型用法代码示例。如果您正苦于以下问题:PHP Zone类的具体用法?PHP Zone怎么用?PHP Zone使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Zone类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: determineZone
private function determineZone()
{
if (PHP_SAPI === 'cli') {
return 'cli';
}
/** @var \Symfony\Component\HttpFoundation\RequestStack $stack */
$stack = $this->app['request_stack'];
$request = $stack->getCurrentRequest() ?: Request::createFromGlobals();
if ($zone = Zone::get($request)) {
return $zone;
}
/** @var \Bolt\EventListener\ZoneGuesser $guesser */
$guesser = $this->app['listener.zone_guesser'];
return $guesser->setZone($request);
}
开发者ID:errogaht,项目名称:bolt,代码行数:15,代码来源:Config.php
示例17: addJquery
/**
* Insert jQuery, if it's not inserted already.
*
* Some of the patterns that 'match' are:
* - jquery.js
* - jquery.min.js
* - jquery-latest.js
* - jquery-latest.min.js
* - jquery-1.8.2.min.js
* - jquery-1.5.js
*
* @param Request $request
* @param Response $response
*/
protected function addJquery(Request $request, Response $response)
{
if (!$this->config->get('general/add_jquery', false) && !$this->config->get('theme/add_jquery', false)) {
return;
}
if (Zone::isFrontend($request) === false) {
return;
}
$html = $response->getContent();
$regex = '/<script(.*)jquery(-latest|-[0-9\\.]*)?(\\.min)?\\.js/';
if (!preg_match($regex, $html)) {
$jqueryfile = $this->resources->getPath('app/view/js/jquery-2.2.4.min.js');
$asset = (new Snippet())->setLocation(Target::BEFORE_JS)->setCallback('<script src="' . $jqueryfile . '"></script>');
$this->injector->inject($asset, $asset->getLocation(), $response);
}
}
开发者ID:bolt,项目名称:bolt,代码行数:30,代码来源:Queue.php
示例18: 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()) {
$this->injector->inject($asset, Target::END_OF_BODY, $response);
} elseif ($asset->getType() === 'stylesheet') {
$this->injector->inject($asset, Target::BEFORE_CSS, $response);
} elseif ($asset->getType() === 'javascript') {
$this->injector->inject($asset, Target::AFTER_JS, $response);
}
}
开发者ID:d-m-,项目名称:bolt,代码行数:19,代码来源:Queue.php
示例19: addJquery
/**
* Insert jQuery, if it's not inserted already.
*
* Some of the patterns that 'match' are:
* - jquery.js
* - jquery.min.js
* - jquery-latest.js
* - jquery-latest.min.js
* - jquery-1.8.2.min.js
* - jquery-1.5.js
*
* @param string $html
*
* @return string HTML
*/
protected function addJquery($html)
{
if (!$this->app['config']->get('general/add_jquery', false) && !$this->app['config']->get('theme/add_jquery', false)) {
return $html;
}
$zone = Zone::FRONTEND;
/** @var RequestStack $requestStack */
$requestStack = $this->app['request_stack'];
if ($request = $requestStack->getCurrentRequest()) {
$zone = Zone::get($request);
}
$regex = '/<script(.*)jquery(-latest|-[0-9\\.]*)?(\\.min)?\\.js/';
if ($zone === Zone::FRONTEND && !preg_match($regex, $html)) {
$jqueryfile = $this->app['resources']->getPath('app/view/js/jquery-2.1.4.min.js');
$asset = new Snippet(Target::BEFORE_JS, '<script src="' . $jqueryfile . '"></script>');
$html = $this->app['asset.injector']->inject($asset, $asset->getLocation(), $html);
}
return $html;
}
开发者ID:nuffer,项目名称:bolt,代码行数:34,代码来源:Queue.php
示例20: onRequest
public function onRequest(GetResponseEvent $event)
{
if (!Zone::isBackend($event->getRequest())) {
return;
}
foreach ($this->config->getRolesAdmin() as $role) {
if ($this->users->isAllowed($role)) {
return;
}
}
throw new AccessDeniedException('Logged in user does not have the correct rights to use this class.');
}
开发者ID:bolt,项目名称:Members,代码行数:12,代码来源:Manager.php
注:本文中的Bolt\Controller\Zone类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论