本文整理汇总了PHP中Zend\View\ViewEvent::setModel方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewEvent::setModel方法的具体用法?PHP ViewEvent::setModel怎么用?PHP ViewEvent::setModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\ViewEvent
的用法示例。
在下文中一共展示了ViewEvent::setModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testReturnsNullWhenCannotSelectRenderer
public function testReturnsNullWhenCannotSelectRenderer()
{
$model = new ViewModel();
$request = new HttpRequest();
$this->event->setModel($model);
$this->event->setRequest($request);
$this->assertNull($this->strategy->selectRenderer($this->event));
}
示例2: testSelectRendererReturnsJsonRendererWhenSwaggerViewModelIsPresentInEvent
public function testSelectRendererReturnsJsonRendererWhenSwaggerViewModelIsPresentInEvent()
{
$event = new ViewEvent();
$event->setName(ViewEvent::EVENT_RENDERER);
$event->setModel(new ViewModel([]));
$renderer = $this->strategy->selectRenderer($event);
$this->assertSame($this->renderer, $renderer);
return $event;
}
示例3: testSelectRendererWhenTemplateFound
public function testSelectRendererWhenTemplateFound()
{
$model = $this->getMock('Zend\\View\\Model\\ModelInterface');
$model->expects($this->at(0))->method('getTemplate')->will($this->returnValue('key1'));
$event = new ViewEvent();
$event->setModel($model);
$result = $this->strategy->selectRenderer($event);
$this->assertSame($this->renderer, $result);
}
示例4: testSelectRendererWithExtension
public function testSelectRendererWithExtension()
{
$model = $this->getMock('Zend\\View\\Model\\ModelInterface');
$model->expects($this->at(0))->method('getTemplate')->will($this->returnValue('test.md'));
$event = new ViewEvent();
$event->setModel($model);
$result = $this->strategy->selectRenderer($event);
$this->assertInstanceOf('Netorare\\View\\Renderer\\MarkdownRenderer', $result);
}
示例5: testSelectRendererReturnsApiBlueprintRendererWhenApiBlueprintViewModelIsPresentInEvent
public function testSelectRendererReturnsApiBlueprintRendererWhenApiBlueprintViewModelIsPresentInEvent()
{
$event = new ViewEvent();
$event->setName(ViewEvent::EVENT_RENDERER);
$event->setModel(new ApiBlueprintModel(array()));
$event->setRequest(new HttpRequest());
$renderer = $this->strategy->selectRenderer($event);
$this->assertSame($this->renderer, $renderer);
return $event;
}
开发者ID:BreiteSeite,项目名称:zf-apigility-documentation-apiblueprint,代码行数:10,代码来源:ApiBlueprintViewStrategyTest.php
示例6: render
/**
*
* @param ModelInterface $model
* @return string
*/
public function render(ModelInterface $model)
{
$event = new ViewEvent();
$event->setName(ViewEvent::EVENT_RENDERER);
$event->setModel($model);
$renderers = $this->view->getEventManager()->triggerEventUntil(function ($result) {
return $result instanceof RendererInterface;
}, $event);
return $renderers->last()->render($model);
}
示例7: testInjectResponseSetsContentTypeHeaderToApiProblemForApiProblemModel
/**
*
*/
public function testInjectResponseSetsContentTypeHeaderToApiProblemForApiProblemModel()
{
$problem = new ApiProblem(500, "Error message");
$model = new ApiProblemModel($problem);
$this->event->setModel($model);
$this->event->setRenderer($this->renderer);
$this->event->setResult('{"foo":"bar"}');
$this->strategy->injectResponse($this->event);
$headers = $this->response->getHeaders();
$this->assertTrue($headers->has('Content-Type'));
$header = $headers->get('Content-Type');
$this->assertEquals('application/problem+json', $header->getFieldValue());
}
示例8: testProperlyFillViewModelHelperIfRendererIsSelected
public function testProperlyFillViewModelHelperIfRendererIsSelected()
{
$model = new ResourceViewModel();
$viewEvent = new ViewEvent();
$viewEvent->setModel($model);
$viewModelHelper = $this->getMock(ViewModel::class, [], [], '', false);
$viewModelHelper->expects($this->once())->method('setRoot')->with($model);
$viewModelHelper->expects($this->once())->method('setCurrent')->with($model);
$helperManager = $this->getMock(HelperPluginManager::class, [], [], '', false);
$helperManager->expects($this->once())->method('setRenderer')->with($this->resourceRenderer);
$helperManager->expects($this->once())->method('get')->with('viewModel')->willReturn($viewModelHelper);
$this->resourceRenderer->expects($this->once())->method('getHelperPluginManager')->willReturn($helperManager);
$this->assertSame($this->resourceRenderer, $this->resourceStrategy->selectRenderer($viewEvent));
}
示例9: onRenderer
/**
* @param ViewEvent $viewEvent
*
* @return PartialRenderer
*/
public function onRenderer(ViewEvent $viewEvent)
{
$model = $viewEvent->getModel();
$config = $this->getOptions()->getConfig();
if ($model instanceof ViewModel && in_array($model->getTemplate(), $config)) {
$success = false;
$cacheContent = $this->getCacheManager()->getItem($model->getTemplate(), $success);
if (true === $success) {
$partialModel = new PartialViewModel();
$partialModel->setIsCached(true);
$partialModel->setCacheContent($cacheContent);
$partialModel->setTemplate($model->getTemplate());
$viewEvent->setModel($model);
}
return $this->getRenderer();
}
}
示例10: 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.
}
示例11: testSelectRendererAndInjectResponse
public function testSelectRendererAndInjectResponse()
{
$renderer = new BlockRenderer();
$strategy = new BlockRendererStrategy($renderer);
$viewEvent = new ViewEvent();
$viewEvent->setModel(new ViewModel());
$this->assertNull($strategy->selectRenderer($viewEvent));
$dummyBlock = new Dummy();
$viewEvent->setModel($dummyBlock);
$this->assertSame($renderer, $strategy->selectRenderer($viewEvent));
$this->assertNull($strategy->injectResponse($viewEvent));
$response = new Response();
$viewEvent->setRenderer($renderer);
$viewEvent->setResult('test');
$viewEvent->setResponse($response);
$strategy->injectResponse($viewEvent);
$this->assertEquals('test', $response->getContent());
}
示例12: 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();
}
示例13: cleanLayout
/**
* remove unwanted or layout related data
*
* basically you rake through the viewmodel for the data you want to use for your template,
* this may not be optimal because you have to rely on the correct naming of the viewmodels
*
* if you get the data you want, you switch to the specific template by adding the conforming resolver
*
* @param \Zend\View\ViewEvent $e
*/
public function cleanLayout(ViewEvent $e)
{
$result = $e->getResult();
$response = $e->getResponse();
$model = $e->getModel();
if ($model->hasChildren()) {
$children = $model->getChildren();
$content = null;
foreach ($children as $child) {
if ($child->captureTo() == 'content') {
$content = $child;
$this->attachViewResolver();
}
}
if (!empty($content)) {
$e->setModel($content);
}
} else {
// attach the own resolver here too ?
// ...
}
}
示例14: testSelectRendererApplicable
public function testSelectRendererApplicable()
{
$e = new ViewEvent();
$e->setModel(new YamlModel());
$this->assertSame($this->renderer, $this->strategy->selectRenderer($e));
}
示例15: testAnotherModel
public function testAnotherModel()
{
$viewEvent = new ViewEvent();
$viewEvent->setModel(new ViewModel());
$this->strategy->selectRenderer($viewEvent);
}