本文整理汇总了PHP中Zend\View\ViewEvent::getResponse方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewEvent::getResponse方法的具体用法?PHP ViewEvent::getResponse怎么用?PHP ViewEvent::getResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\ViewEvent
的用法示例。
在下文中一共展示了ViewEvent::getResponse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: injectResponse
public function injectResponse(ViewEvent $e)
{
$renderer = $e->getRenderer();
if ($renderer !== $this->renderer) {
// Discovered renderer is not ours; do nothing
return;
}
$result = $e->getResult();
if (!is_string($result)) {
// We don't have a string, and thus, no yaml
return;
}
// Populate response
/** @var Http\Response $response */
$response = $e->getResponse();
$response->setContent($result);
/** @var Headers $headers */
$headers = $response->getHeaders();
$contentType = sprintf('application/x-yaml; charset=%s', $this->charset);
$headers->addHeaderLine('content-type', $contentType);
// Add content-transfer-encoding header in charset is multibyte
if (in_array(strtoupper($this->charset), $this->multibyteCharsets)) {
$headers->addHeaderLine('content-transfer-encoding', 'BINARY');
}
}
示例2: injectResponse
/**
* Inject the response with the PDF payload and appropriate Content-Type header
*
* @param ViewEvent $e
* @return void
*/
public function injectResponse(ViewEvent $e)
{
$renderer = $e->getRenderer();
if ($renderer !== $this->renderer) {
// Discovered renderer is not ours; do nothing
return;
}
$result = $e->getResult();
if (!is_string($result)) {
// @todo Potentially throw an exception here since we should *always* get back a result.
return;
}
$response = $e->getResponse();
$response->setContent($result);
$response->getHeaders()->addHeaderLine('content-type', 'application/pdf');
/* @var PdfOptions $pdfOptions */
$pdfOptions = $e->getModel()->getPdfOptions();
$fileName = $pdfOptions->getFileName();
if (isset($fileName)) {
if (substr($fileName, -4) != '.pdf') {
$fileName .= '.pdf';
}
$response->getHeaders()->addHeaderLine('Content-Disposition', 'attachment; filename=' . $fileName);
}
}
示例3: injectResponse
/**
* @param ViewEvent $e
*
* @return null
*
* @throws \Zend\Config\Exception\RuntimeException
* @throws \Zend\Http\Exception\InvalidArgumentException
*/
public function injectResponse(ViewEvent $e)
{
$model = $e->getModel();
if (!$model instanceof ApiProblemModel) {
// Model is not an ApiProblemModel; we cannot handle it here
return null;
}
/** @var Request $request */
$request = $e->getRequest();
/** @var Accept $accept */
$accept = $request->getHeader('Accept');
if (!($accept instanceof Accept && $accept->hasMediaType('text/xml'))) {
return null;
}
$problem = $model->getApiProblem();
$statusCode = $this->getStatusCodeFromApiProblem($problem);
$contentType = 'text/xml';
/** @var Response $response */
$response = $e->getResponse();
$problemData = $problem->toArray();
$xmlWriter = new XmlWriter();
$output = $xmlWriter->processConfig($problemData);
$response->setStatusCode($statusCode);
$response->setContent($output);
$headers = $response->getHeaders();
$headers->addHeaderLine('Content-Type', $contentType);
}
示例4: injectResponse
/**
* Inject the response
*
* Injects the response with the rendered content, and sets the content
* type based on the detection that occurred during renderer selection.
*
* @param ViewEvent $e
*/
public function injectResponse(ViewEvent $e)
{
$renderer = $e->getRenderer();
if ($renderer !== $this->renderer) {
// Discovered renderer is not ours; do nothing
return;
}
$result = $e->getResult();
if (!is_string($result)) {
// We don't have a string, and thus, no JSON
return;
}
$model = $e->getModel();
$contentType = $this->contentType;
$response = $e->getResponse();
if ($model instanceof ApiProblemModel) {
$contentType = 'application/problem+json';
} elseif ($model instanceof HalJsonModel && ($model->isCollection() || $model->isEntity())) {
$contentType = 'application/hal+json';
}
/** @var Response $response */
$response->setContent($result);
$headers = $response->getHeaders();
$headers->addHeaderLine('content-type', $contentType);
}
示例5: injectResponse
/**
* Inject the response
*
* Injects the response with the rendered content, and sets the content
* type based on the detection that occurred during renderer selection.
*
* @param ViewEvent $e
*/
public function injectResponse(ViewEvent $e)
{
$renderer = $e->getRenderer();
if ($renderer !== $this->renderer) {
// Discovered renderer is not ours; do nothing
return;
}
$result = $e->getResult();
if (!is_string($result)) {
// We don't have a string, and thus, no JSON
return;
}
$model = $e->getModel();
$contentType = $this->contentType;
$response = $e->getResponse();
if ($this->renderer->isApiProblem()) {
$contentType = 'application/api-problem+json';
$statusCode = $this->getStatusCodeFromApiProblem($this->renderer->getApiProblem());
$response->setStatusCode($statusCode);
} elseif ($model instanceof RestfulJsonModel && $model->isApiProblem()) {
$contentType = 'application/api-problem+json';
$statusCode = $this->getStatusCodeFromApiProblem($model->getPayload());
$response->setStatusCode($statusCode);
} elseif ($model instanceof RestfulJsonModel && ($model->isHalCollection() || $model->isHalResource())) {
$contentType = 'application/hal+json';
}
// Populate response
$response->setContent($result);
$headers = $response->getHeaders();
$headers->addHeaderLine('content-type', $contentType);
}
示例6: injectResponse
/**
* @param ViewEvent $ev
* @return void
*/
public function injectResponse(ViewEvent $ev)
{
if ($ev->getRenderer() === $this->renderer) {
$result = $ev->getResult();
$response = $ev->getResponse();
$response->setContent($result);
}
}
示例7: processRcmResponses
/**
* Check for not authorized and redirect to the login page on 401.
*
* @param ViewEvent $event Zend MVC Event object
*
* @return null
*/
public function processRcmResponses(ViewEvent $event)
{
$response = $event->getResponse();
if (!$response instanceof RcmResponse) {
return null;
}
$this->responseHandler->processResponse($response);
return null;
}
示例8: response
public function response(ViewEvent $event)
{
$renderer = $event->getRenderer();
if ($renderer instanceof IcalendarRenderer) {
$response = $event->getResponse();
$response->getHeaders()->addHeaderLine('Content-type', 'text/calendar; charset=utf-8');
$response->setContent($event->getResult());
}
}
示例9: injectResponse
/**
* Populate the response object from the view
*
* Populates the content of the response object from the view rendering
* results.
*
* @param ViewEvent $event
* @return void
*/
public function injectResponse(ViewEvent $event)
{
if ($event->getRenderer() !== $this->renderer) {
return;
}
$result = $event->getResult();
$response = $event->getResponse();
$response->setContent($result);
}
示例10: injectResponse
/**
* Sets the response based on image returned by the renderer
*
* @param ViewEvent $e
* @return void
*/
public function injectResponse(ViewEvent $e)
{
$model = $e->getModel();
if ($model instanceof ImageModel) {
$result = $e->getResult();
$response = $e->getResponse();
$response->setContent($result);
$response->getHeaders()->addHeaderLine('Content-type', $this->getMimeType($model->getFormat()));
}
}
示例11: injectResponse
public function injectResponse(ViewEvent $e)
{
$renderer = $e->getRenderer();
if ($renderer !== $this->renderer) {
return false;
}
$result = $e->getResult();
$response = $e->getResponse();
$response->setContent($result);
}
示例12: injectResponse
/**
* @param ViewEvent $e
*/
public function injectResponse(ViewEvent $e)
{
if (!$this->model instanceof ViewModel) {
return;
}
$response = $e->getResponse();
if (!method_exists($response, 'getHeaders')) {
return;
}
$headers = $response->getHeaders();
$headers->addHeaderLine('Content-Type', 'application/vnd.swagger+json');
}
示例13: injectResponse
/**
* @param ViewEvent $e
*/
public function injectResponse(ViewEvent $e)
{
if (!$this->model instanceof ApiBlueprintModel) {
return;
}
$response = $e->getResponse();
if (!method_exists($response, 'getHeaders')) {
return;
}
$headers = $response->getHeaders();
$headers->addHeaderLine('Content-Type', 'text/vnd.apiblueprint+markdown');
$response->setContent($e->getResult());
}
开发者ID:weierophinney,项目名称:zf-apigility-documentation-apiblueprint,代码行数:16,代码来源:ApiBlueprintViewStrategy.php
示例14: injectResponse
/**
* Inject the response with the feed payload and appropriate Content-Type header
*
* @param ViewEvent $e
* @return void
* @throws \Zend\Http\Exception\InvalidArgumentException
*/
public function injectResponse(ViewEvent $e)
{
$renderer = $e->getRenderer();
if ($renderer !== $this->renderer) {
return;
}
$result = $e->getResult();
/** @var HttpResponse $response */
$response = $e->getResponse();
$response->setContent($result);
$headers = $response->getHeaders();
//$headers->addHeaderLine('Content-length', strlen($result));
$headers->addHeaderLine('content-type', 'text/xml');
}
示例15: injectResponse
public function injectResponse(ViewEvent $e)
{
$model = $e->getModel();
if (!$model instanceof \Stjornvisi\View\Model\IcalModel) {
// no JsonModel; do nothing
return;
}
$result = $e->getResult();
// Populate response
$response = $e->getResponse();
$response->setContent($result);
$headers = $response->getHeaders();
$headers->addHeaderLine('content-type', 'text/calendar; charset=utf-8');
}