本文整理汇总了PHP中Zend\Http\PhpEnvironment\Request::isXmlHttpRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::isXmlHttpRequest方法的具体用法?PHP Request::isXmlHttpRequest怎么用?PHP Request::isXmlHttpRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\Http\PhpEnvironment\Request
的用法示例。
在下文中一共展示了Request::isXmlHttpRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callWidget
/**
* Call widget
*
* @param string $position
* @param integer $pageId
* @param integer $userRole
* @param array $widgetInfo
* @param boolean $useLayout
* @throws \Page\Exception\PageException
* @return string|boolean
*/
protected function callWidget($position, $pageId, $userRole, array $widgetInfo, $useLayout = true)
{
// don't call any widgets
if (true === self::$widgetRedirected) {
return false;
}
// check a widget visibility
if ($userRole != AclBaseModel::DEFAULT_ROLE_ADMIN) {
if (!empty($widgetInfo['hidden']) && in_array($userRole, $widgetInfo['hidden'])) {
return false;
}
}
// call the widget
$widget = $this->getView()->{$widgetInfo['widget_name']}();
// check the widget
if (!$widget instanceof IPageWidget) {
throw new PageException(sprintf($widgetInfo['widget_name'] . ' must be an object implementing IPageWidget'));
}
// init the widget
$widget->setPageId($pageId)->setWidgetPosition($position)->setWidgetConnectionId($widgetInfo['widget_connection_id']);
$widgetCacheName = null;
if ((int) $widgetInfo['widget_cache_ttl']) {
// generate a cache name
$widgetCacheName = CacheUtility::getCacheName($widgetInfo['widget_name'], [$widgetInfo['widget_connection_id']]);
// check the widget data in a cache
if (null !== ($cachedWidgetData = $this->dynamicCache->getItem($widgetCacheName))) {
// check a local widget lifetime
if ($cachedWidgetData['widget_expire'] >= time()) {
// include widget's css and js files
if (false !== $cachedWidgetData['widget_content'] && !$this->request->isXmlHttpRequest()) {
$widget->includeJsCssFiles();
}
return $cachedWidgetData['widget_content'];
}
// clear cache
$this->dynamicCache->removeItem($widgetCacheName);
}
}
if (false !== ($widgetContent = $widget->getContent())) {
self::$widgetRedirected = $widget->isWidgetRedirected();
// include widget's css and js files
if (!$this->request->isXmlHttpRequest()) {
$widget->includeJsCssFiles();
}
// add the widget's layout
if ($useLayout) {
if (!empty($widgetInfo['widget_layout'])) {
$widgetContent = $this->getView()->partial($this->layoutPath . $widgetInfo['widget_layout'], ['title' => $this->getView()->pageWidgetTitle($widgetInfo), 'content' => $widgetContent]);
} else {
$widgetContent = $this->getView()->partial($this->layoutPath . 'default', ['title' => $this->getView()->pageWidgetTitle($widgetInfo), 'content' => $widgetContent]);
}
}
}
// cache the widget data
if ($widgetCacheName) {
$this->dynamicCache->setItem($widgetCacheName, ['widget_content' => $widgetContent, 'widget_expire' => time() + $widgetInfo['widget_cache_ttl']]);
}
return $widgetContent;
}
示例2: it_should_build_a_json_model_when_request_is_xml_http_request
/**
* @param \Zend\Http\PhpEnvironment\Request $request
* @param \Phpro\SmartCrud\Service\SmartServiceResult $SmartServiceResult
* @param \StdClass $entity
*/
public function it_should_build_a_json_model_when_request_is_xml_http_request($request, $SmartServiceResult)
{
$request->isXmlHttpRequest()->willReturn(true);
$this->build($request, $SmartServiceResult, 'create')->shouldBeAnInstanceOf('\\Zend\\View\\Model\\JsonModel');
}