当前位置: 首页>>代码示例>>PHP>>正文


PHP ViewEvent::getModel方法代码示例

本文整理汇总了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;
 }
开发者ID:bedrest,项目名称:framework-zendframework2,代码行数:11,代码来源:ContentNegotiationStrategy.php

示例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);
 }
开发者ID:antarus,项目名称:mystra-pve,代码行数:33,代码来源:HalJsonStrategy.php

示例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);
 }
开发者ID:davidbrabrand,项目名称:PhlyRestfully,代码行数:39,代码来源:RestfulJsonStrategy.php

示例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;
 }
开发者ID:ranxin1022,项目名称:zf2,代码行数:38,代码来源:FeedStrategy.php

示例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);
 }
开发者ID:old-town,项目名称:workflow-designer-server,代码行数:35,代码来源:ApiProblemInjectResponse.php

示例6: selectRenderer

 public function selectRenderer(ViewEvent $e)
 {
     if (!$this->renderer->canRender($e->getModel())) {
         return false;
     }
     return $this->renderer;
 }
开发者ID:skillfish,项目名称:zf3-smarty-module,代码行数:7,代码来源:Strategy.php

示例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;
     }
 }
开发者ID:ninahuanca,项目名称:zf2,代码行数:39,代码来源:JsonStrategy.php

示例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);
 }
开发者ID:eltondias,项目名称:Relogio,代码行数:37,代码来源:FeedStrategy.php

示例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;
 }
开发者ID:robertodormepoco,项目名称:zf2,代码行数:39,代码来源:JsonStrategy.php

示例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;
 }
开发者ID:uthando-cms,项目名称:uthando-newsletter,代码行数:14,代码来源:NewsletterStrategy.php

示例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;
 }
开发者ID:halaxa,项目名称:zf2-latte,代码行数:14,代码来源:LatteStrategy.php

示例12: selectRenderer

 public function selectRenderer(ViewEvent $e)
 {
     $model = $e->getModel();
     if ($model instanceof YamlModel) {
         return $this->renderer;
     }
     return null;
 }
开发者ID:kidaa,项目名称:evedata,代码行数:8,代码来源:YamlStrategy.php

示例13: selectRenderer

 /**
  *
  * @param ViewEvent $e
  * @return RendererInterface|null
  */
 public function selectRenderer(ViewEvent $e)
 {
     $model = $e->getModel();
     if (!$model instanceof BlockInterface) {
         return;
     }
     return $this->renderer;
 }
开发者ID:adamdyson,项目名称:ConLayout,代码行数:13,代码来源:BlockRendererStrategy.php

示例14: selectRenderer

 /**
  * @param  ViewEvent $ev
  * @return SmartyRenderer
  */
 public function selectRenderer(ViewEvent $ev)
 {
     if ($this->renderer->canRender($ev->getModel())) {
         return $this->renderer;
     } else {
         return null;
     }
 }
开发者ID:ngyuki,项目名称:zf2-smarty,代码行数:12,代码来源:SmartyStrategy.php

示例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;
 }
开发者ID:krsreenatha,项目名称:php.ug,代码行数:17,代码来源:IcalendarStrategy.php


注:本文中的Zend\View\ViewEvent::getModel方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。