本文整理匯總了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);
}
}