本文整理汇总了PHP中Bolt\Controller\Zone::isFrontend方法的典型用法代码示例。如果您正苦于以下问题:PHP Zone::isFrontend方法的具体用法?PHP Zone::isFrontend怎么用?PHP Zone::isFrontend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bolt\Controller\Zone
的用法示例。
在下文中一共展示了Zone::isFrontend方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testControllerZone
/**
* @covers \Bolt\Controller\Zone::get
* @covers \Bolt\Controller\Zone::isFrontend
*/
public function testControllerZone()
{
$app = $this->getApp();
$this->setRequest(Request::create('/'));
$request = $this->getRequest();
$kernel = $this->getMock('Symfony\\Component\\HttpKernel\\HttpKernelInterface');
$app['dispatcher']->dispatch(KernelEvents::REQUEST, new GetResponseEvent($kernel, $request, HttpKernelInterface::MASTER_REQUEST));
$this->assertEquals('frontend', Zone::get($request));
$this->assertTrue(Zone::isFrontend($request));
}
示例2: 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);
}
示例3: parseTextQuery
/**
* Parse textquery into useable arguments.
*
* This is tightly coupled to $this->getContent()
*
* @see $this->decodeContentQuery()
*
* @param $textquery
* @param array $decoded a pre-set decoded array to fill
* @param array $metaParameters meta parameters
* @param array $ctypeParameters contenttype parameters
*/
private function parseTextQuery($textquery, array &$decoded, array &$metaParameters, array &$ctypeParameters)
{
// Our default callback
$decoded['queries_callback'] = [$this, 'executeGetContentQueries'];
// Some special cases, like 'entry/1' or 'page/about' need to be caught before further processing.
if (preg_match('#^/?([a-z0-9_-]+)/([0-9]+)$#i', $textquery, $match)) {
// like 'entry/12' or '/page/12345'
$decoded['contenttypes'] = $this->decodeContentTypesFromText($match[1]);
$decoded['return_single'] = true;
// if allow_numeric_slug option is set on contenttype, interpret number as slug instead of id
$contenttype = $this->getContentType($decoded['contenttypes'][0]);
$field = $contenttype['allow_numeric_slugs'] === true ? 'slug' : 'id';
$ctypeParameters[$field] = $match[2];
} elseif (preg_match('#^/?([a-z0-9_(\\),-]+)/search(/([0-9]+))?$#i', $textquery, $match)) {
// like 'page/search or '(entry,page)/search'
$decoded['contenttypes'] = $this->decodeContentTypesFromText($match[1]);
$metaParameters['order'] = [$this, 'compareSearchWeights'];
if (count($match) >= 3) {
$metaParameters['limit'] = $match[3];
}
$decoded['queries_callback'] = [$this, 'executeGetContentSearch'];
} elseif (preg_match('#^/?([a-z0-9_-]+)/([a-z0-9_-]+)$#i', $textquery, $match)) {
// like 'page/lorem-ipsum-dolor' or '/page/home'
$decoded['contenttypes'] = $this->decodeContentTypesFromText($match[1]);
$decoded['return_single'] = true;
$ctypeParameters['slug'] = $match[2];
} elseif (preg_match('#^/?([a-z0-9_-]+)/(latest|first)/([0-9]+)$#i', $textquery, $match)) {
// like 'page/latest/5'
$decoded['contenttypes'] = $this->decodeContentTypesFromText($match[1]);
if (!isset($metaParameters['order']) || $metaParameters['order'] === false) {
$metaParameters['order'] = 'datepublish ' . ($match[2] == 'latest' ? 'DESC' : 'ASC');
}
if (!isset($metaParameters['limit'])) {
$metaParameters['limit'] = $match[3];
}
} elseif (preg_match('#^/?([a-z0-9_-]+)/random/([0-9]+)$#i', $textquery, $match)) {
// like 'page/random/4'
$decoded['contenttypes'] = $this->decodeContentTypesFromText($match[1]);
$dboptions = $this->app['config']->get('general/database');
$metaParameters['order'] = $dboptions['randomfunction'];
// 'RAND()' or 'RANDOM()'
if (!isset($metaParameters['limit'])) {
$metaParameters['limit'] = $match[2];
}
} else {
$decoded['contenttypes'] = $this->decodeContentTypesFromText($textquery);
if (isset($ctypeParameters['id']) && is_numeric($ctypeParameters['id'])) {
$decoded['return_single'] = true;
}
}
// When using from the frontend, we assume (by default) that we only want published items,
// unless something else is specified explicitly
$request = $this->app['request_stack']->getCurrentRequest();
$isFrontend = $request ? Zone::isFrontend($request) : true;
if ($isFrontend && empty($ctypeParameters['status'])) {
$ctypeParameters['status'] = 'published';
}
if (isset($metaParameters['returnsingle'])) {
$decoded['return_single'] = $metaParameters['returnsingle'];
unset($metaParameters['returnsingle']);
}
}
示例4: 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);
}
}