本文整理汇总了PHP中Zend\View\ViewEvent::setResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewEvent::setResponse方法的具体用法?PHP ViewEvent::setResponse怎么用?PHP ViewEvent::setResponse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\ViewEvent
的用法示例。
在下文中一共展示了ViewEvent::setResponse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->response = new Response();
$this->event = new ViewEvent();
$this->event->setResponse($this->response);
$this->renderer = new HalJsonRenderer(new ApiProblemRenderer());
$this->strategy = new HalJsonStrategy($this->renderer);
}
示例2: testNonStringResultDoesNotInjectResponse
public function testNonStringResultDoesNotInjectResponse()
{
$this->event->setResponse($this->response);
$this->event->setRenderer($this->renderer);
$this->event->setResult($this->response);
$this->strategy->injectResponse($this->event);
$this->assertResponseNotInjected();
}
示例3: testResponseContentSetToResultIfNotEmpty
public function testResponseContentSetToResultIfNotEmpty()
{
$this->renderer->placeholder('article')->set('Article Content');
$this->renderer->placeholder('content')->set('Content');
$event = new ViewEvent();
$event->setResponse($this->response)->setRenderer($this->renderer)->setResult('Result Content');
$this->strategy->injectResponse($event);
$content = $this->response->getContent();
$this->assertEquals('Result Content', $content);
}
示例4: testResponseHeadersWithFileName
public function testResponseHeadersWithFileName()
{
$model = new PdfModel();
$model->setTemplate('basic.phtml');
$model->setOption('filename', 'testPdfFileName');
$this->event->setModel($model);
$this->event->setResponse($this->response);
$this->event->setRenderer($this->renderer);
$this->event->setResult($this->renderer->render($model));
$this->strategy->injectResponse($this->event);
$headers = $this->event->getResponse()->getHeaders();
$contentDisposition = $headers->get('Content-Disposition');
$this->assertInstanceOf('Zend\\Http\\Header\\ContentDisposition', $contentDisposition);
$this->assertEquals($contentDisposition->getFieldValue(), 'attachment; filename=testPdfFileName.pdf');
ob_end_flush();
// Clear out any buffers held by renderers.
}
示例5: testResponseHeadersWithFileName
public function testResponseHeadersWithFileName()
{
$model = $this->serviceManager->get('PdfModel');
$model->setTemplate('basic.phtml');
$model->getPdfOptions()->setFilename('testPdfFileName');
$model->getPdfOptions()->setFooterLines([['text' => 'top line', 'position' => 'center', 'font' => ['family' => 'Helvetica', 'weight' => 'normal', 'size' => 8]], ['text' => 'second line', 'position' => 'left', 'font' => ['family' => 'Helvetica', 'weight' => 'normal', 'size' => 8]], ['text' => 'third line', 'position' => 'right', 'font' => ['family' => 'Helvetica', 'weight' => 'normal', 'size' => 8]]]);
$model->getPdfOptions()->setHeaderLines([['text' => 'first line', 'position' => 'center', 'font' => ['family' => 'Helvetica', 'weight' => 'normal', 'size' => 8]]]);
$this->event->setModel($model);
$this->event->setResponse($this->response);
$this->event->setRenderer($this->renderer);
$this->event->setResult($this->renderer->render($model));
$this->strategy->injectResponse($this->event);
$headers = $this->event->getResponse()->getHeaders();
$contentDispositionHeader = $headers->get('Content-Disposition');
$this->assertInstanceof('Zend\\Http\\Header\\ContentDisposition', $contentDispositionHeader);
$this->assertEquals($contentDispositionHeader->getFieldValue(), 'attachment; filename=testPdfFileName.pdf');
ob_end_flush();
}
示例6: getEvent
/**
* Create and return ViewEvent used by render()
*
* @return ViewEvent
*/
protected function getEvent()
{
$event = new ViewEvent();
$event->setTarget($this);
if (null !== ($request = $this->getRequest())) {
$event->setRequest($request);
}
if (null !== ($response = $this->getResponse())) {
$event->setResponse($response);
}
return $event;
}
示例7: testProcessRcmResponses
/**
* Test Process Rcm Responses
*
* @return void
*
* @covers \Rcm\EventListener\ViewEventListener::processRcmResponses
*/
public function testProcessRcmResponses()
{
$event = new ViewEvent();
$response = new Response();
$response->setStatusCode(404);
$mockResponseHandler = $this->getMockBuilder('Rcm\\Service\\ResponseHandler')->disableOriginalConstructor()->getMock();
$mockResponseHandler->expects($this->once())->method('processResponse');
$event->setResponse($response);
/** @var \Rcm\Service\ResponseHandler $mockResponseHandler */
$listener = new ViewEventListener($mockResponseHandler);
$listener->processRcmResponses($event);
}
示例8: getPluginViewData
/**
* Get a plugin instance rendered view.
*
* @param string $pluginName Plugin name
* @param integer $pluginInstanceId Plugin Instance Id
* @param array $pluginInstanceConfig Plugin Instance Config
*
* @return array
* @throws \Rcm\Exception\InvalidPluginException
* @throws \Rcm\Exception\PluginReturnedResponseException
*/
public function getPluginViewData($pluginName, $pluginInstanceId, $pluginInstanceConfig)
{
/** @var \Rcm\Plugin\PluginInterface $controller */
$controller = $this->getPluginController($pluginName);
if (!is_a($controller, '\\Rcm\\Plugin\\PluginInterface')) {
throw new InvalidPluginException('Plugin ' . $controller . ' must implement the PluginInterface');
}
$controller->setRequest($this->request);
$response = new Response();
$controller->setResponse($response);
/** @var \Zend\Mvc\MvcEvent $event */
$event = $controller->getEvent();
$event->setRequest($this->request);
$event->setResponse($response);
$controller->setEvent($event);
$viewModel = $controller->renderInstance($pluginInstanceId, $pluginInstanceConfig);
if ($viewModel instanceof ResponseInterface) {
$event = new ViewEvent();
$event->setResponse($viewModel);
$this->eventManager->trigger(ViewEvent::EVENT_RESPONSE, $event);
return null;
}
/** @var \Zend\View\Helper\Headlink $headlink */
$headlink = $this->renderer->plugin('headlink');
/** @var \Zend\View\Helper\HeadScript $headScript */
$headScript = $this->renderer->plugin('headscript');
$oldContainer = $headlink->getContainer();
$linkContainer = new Container();
$headlink->setContainer($linkContainer);
$oldScriptContainer = $headScript->getContainer();
$headScriptContainer = new Container();
$headScript->setContainer($headScriptContainer);
$html = $this->renderer->render($viewModel);
$css = $headlink->getContainer()->getArrayCopy();
$script = $headScript->getContainer()->getArrayCopy();
$return = ['html' => $html, 'css' => $this->getContainerSrc($css), 'js' => $this->getContainerSrc($script), 'editJs' => '', 'editCss' => '', 'displayName' => '', 'tooltip' => '', 'icon' => '', 'siteWide' => false, 'md5' => '', 'fromCache' => false, 'canCache' => false, 'pluginName' => $pluginName, 'pluginInstanceId' => $pluginInstanceId];
if (isset($this->config['rcmPlugin'][$pluginName]['display'])) {
$return['displayName'] = $this->config['rcmPlugin'][$pluginName]['display'];
}
if (isset($this->config['rcmPlugin'][$pluginName]['tooltip'])) {
$return['tooltip'] = $this->config['rcmPlugin'][$pluginName]['tooltip'];
}
if (isset($this->config['rcmPlugin'][$pluginName]['icon'])) {
$return['icon'] = $this->config['rcmPlugin'][$pluginName]['icon'];
}
if (isset($this->config['rcmPlugin'][$pluginName]['canCache'])) {
$return['canCache'] = $this->config['rcmPlugin'][$pluginName]['canCache'];
}
$headlink->setContainer($oldContainer);
$headScript->setContainer($oldScriptContainer);
return $return;
}
示例9: createBaseViewEvent
/**
* Creates a ViewEvent object with some dependencies already injected
* @return ViewEvent
*/
private function createBaseViewEvent()
{
$e = new ViewEvent();
$e->setResponse(new Response());
return $e;
}