本文整理汇总了PHP中Zend\View\ViewEvent::getModel方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewEvent::getModel方法的具体用法?PHP ViewEvent::getModel怎么用?PHP ViewEvent::getModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend\View\ViewEvent
的用法示例。
在下文中一共展示了ViewEvent::getModel方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: selectRenderer
/**
* @param \Zend\View\ViewEvent $e
* @return \BedRest\Framework\Zend2\View\Renderer\ContentNegotiationRenderer
*/
public function selectRenderer(ViewEvent $e)
{
if (!$e->getModel() instanceof ViewModel) {
return;
}
return $this->renderer;
}
示例2: 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);
}
示例3: 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);
}
示例4: selectRenderer
/**
* Detect if we should use the FeedRenderer based on model type and/or
* Accept header
*
* @param ViewEvent $e
* @return null|FeedRenderer
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if ($model instanceof Model\FeedModel) {
// FeedModel found
return $this->renderer;
}
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
// Not an HTTP request; cannot autodetermine
return;
}
$headers = $request->headers();
if ($headers->has('accept')) {
$accept = $headers->get('accept');
foreach ($accept->getPrioritized() as $mediaType) {
if (0 === strpos($mediaType, 'application/rss+xml')) {
// application/rss+xml Accept header found
$this->renderer->setFeedType('rss');
return $this->renderer;
}
if (0 === strpos($mediaType, 'application/atom+xml')) {
// application/atom+xml Accept header found
$this->renderer->setFeedType('atom');
return $this->renderer;
}
}
}
// Not matched!
return;
}
示例5: 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);
}
示例6: selectRenderer
public function selectRenderer(ViewEvent $e)
{
if (!$this->renderer->canRender($e->getModel())) {
return false;
}
return $this->renderer;
}
示例7: selectRenderer
/**
* Detect if we should use the JsonRenderer based on model type and/or
* Accept header
*
* @param ViewEvent $e
* @return null|JsonRenderer
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if ($model instanceof Model\JsonModel) {
// JsonModel found
return $this->renderer;
}
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
// Not an HTTP request; cannot autodetermine
return;
}
$headers = $request->getHeaders();
if (!$headers->has('accept')) {
return;
}
$accept = $headers->get('Accept');
if (($match = $accept->match('application/json, application/javascript')) == false) {
return;
}
if ($match->getTypeString() == 'application/json') {
// application/json Accept header found
return $this->renderer;
}
if ($match->getTypeString() == 'application/javascript') {
// application/javascript Accept header found
if (false != ($callback = $request->getQuery()->get('callback'))) {
$this->renderer->setJsonpCallback($callback);
}
return $this->renderer;
}
}
示例8: injectResponse
/**
* Inject the response with the feed 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) && !$result instanceof Feed) {
// We don't have a string, and thus, no feed
return;
}
// If the result is a feed, export it
if ($result instanceof Feed) {
$result = $result->export($renderer->getFeedType());
}
// Get the content-type header based on feed type
$feedType = $renderer->getFeedType();
$feedType = 'rss' == $feedType ? 'application/rss+xml' : 'application/atom+xml';
$model = $e->getModel();
$charset = '';
if ($model instanceof Model\FeedModel) {
$feed = $model->getFeed();
$charset = '; charset=' . $feed->getEncoding() . ';';
}
// Populate response
$response = $e->getResponse();
$response->setContent($result);
$headers = $response->getHeaders();
$headers->addHeaderLine('content-type', $feedType . $charset);
}
示例9: selectRenderer
/**
* Detect if we should use the JsonRenderer based on model type and/or
* Accept header
*
* @param ViewEvent $e
* @return null|JsonRenderer
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if ($model instanceof Model\JsonModel) {
// JsonModel found
return $this->renderer;
}
$request = $e->getRequest();
if (!$request instanceof HttpRequest) {
// Not an HTTP request; cannot autodetermine
return;
}
$headers = $request->getHeaders();
if ($headers->has('accept')) {
$accept = $headers->get('Accept');
foreach ($accept->getPrioritized() as $mediaType) {
if (0 === strpos($mediaType, 'application/json')) {
// application/json Accept header found
return $this->renderer;
}
if (0 === strpos($mediaType, 'application/javascript')) {
// application/javascript Accept header found
if (false != ($callback = $request->getQuery()->get('callback'))) {
$this->renderer->setJsonpCallback($callback);
}
return $this->renderer;
}
}
}
// Not matched!
return;
}
示例10: selectRenderer
/**
* Detect if we should use the NewsletterRenderer based on model type
*
* @param ViewEvent $e
* @return null|NewsletterRenderer
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if ($model instanceof NewsletterModel) {
return $this->renderer;
}
return false;
}
示例11: selectRenderer
/**
* Determine if the renderer can load the requested template.
*
* @param ViewEvent $e
* @return bool|LatteRenderer
*/
public function selectRenderer(ViewEvent $e)
{
$tplPath = $this->resolver->resolve($e->getModel()->getTemplate(), $this->renderer);
if ($tplPath) {
return $this->renderer;
}
return false;
}
示例12: selectRenderer
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if ($model instanceof YamlModel) {
return $this->renderer;
}
return null;
}
示例13: selectRenderer
/**
*
* @param ViewEvent $e
* @return RendererInterface|null
*/
public function selectRenderer(ViewEvent $e)
{
$model = $e->getModel();
if (!$model instanceof BlockInterface) {
return;
}
return $this->renderer;
}
示例14: selectRenderer
/**
* @param ViewEvent $ev
* @return SmartyRenderer
*/
public function selectRenderer(ViewEvent $ev)
{
if ($this->renderer->canRender($ev->getModel())) {
return $this->renderer;
} else {
return null;
}
}
示例15: selectRenderer
/**
* Detect if we should use the IcalendarRenderer based on model type and/or
* Accept header
*
* @param \Zend\View\ViewEvent $oEvent
*
* @return null|\Phpug\Mvc\Renderer\IcalendarRenderer
*/
public function selectRenderer(\Zend\View\ViewEvent $oEvent)
{
$oModel = $oEvent->getModel();
// No IcalendarModel; do nothing
if (!$oModel instanceof IcalendarModel) {
return;
}
return $this->renderer;
}