本文整理汇总了PHP中Magento\Framework\App\Response\Http::representJson方法的典型用法代码示例。如果您正苦于以下问题:PHP Http::representJson方法的具体用法?PHP Http::representJson怎么用?PHP Http::representJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\App\Response\Http
的用法示例。
在下文中一共展示了Http::representJson方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: aroundDispatch
/**
* Call method around dispatch frontend action
*
* @param FrontControllerInterface $subject
* @param \Closure $proceed
* @param RequestInterface $request
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
* @SuppressWarnings(PHPMD)
*/
public function aroundDispatch(FrontControllerInterface $subject, \Closure $proceed, RequestInterface $request)
{
$startTime = microtime(true);
if (isset($_SERVER['REQUEST_TIME_FLOAT'])) {
$startTime = $_SERVER['REQUEST_TIME_FLOAT'];
}
/** @var \Magento\Framework\App\Request\Http $request */
if (strpos($request->getOriginalPathInfo(), 'searchautocomplete/ajax/suggest') !== false) {
$this->result->init();
$proceed($request);
#require for init translations
$request->setControllerModule('Magento_CatalogSearch');
$request->setDispatched(true);
$identifier = 'QUERY_' . $this->storeManager->getStore()->getId() . '_' . md5($request->getParam('q'));
if ($result = $this->cache->load($identifier)) {
$result = \Zend_Json::decode($result);
$result['time'] = round(microtime(true) - $startTime, 4);
$result['cache'] = true;
$data = \Zend_Json::encode($result);
} else {
// mirasvit core event
$this->eventManager->dispatch('core_register_urlrewrite');
$result = $this->result->toArray();
$result['success'] = true;
$result['time'] = round(microtime(true) - $startTime, 4);
$result['cache'] = false;
$data = \Zend_Json::encode($result);
$this->cache->save($data, $identifier, [\Magento\PageCache\Model\Cache\Type::CACHE_TAG]);
}
$this->response->setPublicHeaders(3600);
return $this->response->representJson($data);
} else {
return $proceed($request);
}
}
示例2: testRepresentJson
/**
* Test setting body in JSON format
*/
public function testRepresentJson()
{
$this->model->setHeader('Content-Type', 'text/javascript');
$this->model->representJson('json_string');
$this->assertEquals('application/json', $this->model->getHeader('Content-Type')->getFieldValue());
$this->assertEquals('json_string', $this->model->getBody('default'));
}
示例3: representJson
/**
* {@inheritdoc}
*/
public function representJson($content)
{
$pluginInfo = $this->pluginList->getNext($this->subjectType, 'representJson');
if (!$pluginInfo) {
return parent::representJson($content);
} else {
return $this->___callPlugins('representJson', func_get_args(), $pluginInfo);
}
}