本文整理汇总了PHP中Zend\View\ViewEvent::setResult方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewEvent::setResult方法的具体用法?PHP ViewEvent::setResult怎么用?PHP ViewEvent::setResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\ViewEvent
的用法示例。
在下文中一共展示了ViewEvent::setResult方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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();
}
示例2: 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());
}
示例3: 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.
}
示例4: 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();
}
示例5: attachPDFtransformer
/**
* Transform the HTML to PDF,
* this is a post-rendering-process
*
* put in here everything related to the transforming-process like options
*
* @param \Zend\View\ViewEvent $e
*/
public function attachPDFtransformer(ViewEvent $e)
{
//$renderer = $e->getRenderer();
$result = $e->getResult();
$response = $e->getResponse();
// the handles are for temporary files
error_reporting(0);
foreach (array(self::RENDER_FULL, self::RENDER_WITHOUT_PDF, self::RENDER_WITHOUT_ATTACHMENTS) as $render) {
$handles = array();
try {
$pdf = new extern\mPDFderive();
$pdf->SetImportUse();
// create bookmark list in Acrobat Reader
$pdf->h2bookmarks = array('H1' => 0, 'H2' => 1, 'H3' => 2);
$pdf->WriteHTML($result);
// Output of the Images
if (self::RENDER_FULL == $render || self::RENDER_WITHOUT_PDF == $render) {
if (is_array($this->appendImage) && !empty($this->appendImage)) {
foreach ($this->appendImage as $imageAttachment) {
$content = $imageAttachment->getContent();
$url = 'data:image/' . $imageAttachment->getType() . ';base64,' . base64_encode($content);
$html = '<a name="attachment_' . $imageAttachment->getId() . '"><img src="' . $url . '" /><br /></a>';
$pdf->WriteHTML($html);
}
}
}
// Temp Files PDF
if (self::RENDER_FULL == $render) {
if (is_array($this->appendPDF) && !empty($this->appendPDF)) {
foreach ($this->appendPDF as $pdfAttachment) {
$content = $pdfAttachment->getContent();
$tmpHandle = tmpfile();
$handles[] = $tmpHandle;
fwrite($tmpHandle, $content);
fseek($tmpHandle, 0);
}
}
}
// Output of the PDF
foreach ($handles as $handle) {
$meta_data = stream_get_meta_data($handle);
$filename = $meta_data["uri"];
$pdf->WriteHTML($filename);
$pagecount = $pdf->SetSourceFile($filename);
for ($pages = 0; $pages < $pagecount; $pages++) {
$pdf->AddPage();
$pdf->WriteHTML(' pages: ' . $pagecount);
$tx = $pdf->ImportPage($pages + 1);
$pdf->UseTemplate($tx);
}
}
$pdf_result = $pdf->Output();
$e->setResult($pdf_result);
// delete all temporary Files again
foreach ($handles as $handle) {
fclose($handle);
}
break;
} catch (\Exception $e) {
}
}
error_reporting(E_ALL);
}