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


PHP ViewModel::terminate方法代码示例

本文整理汇总了PHP中Zend\View\Model\ViewModel::terminate方法的典型用法代码示例。如果您正苦于以下问题:PHP ViewModel::terminate方法的具体用法?PHP ViewModel::terminate怎么用?PHP ViewModel::terminate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\View\Model\ViewModel的用法示例。


在下文中一共展示了ViewModel::terminate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: extractCacheTags

 /**
  *
  * @param ViewModel $viewModel
  */
 private function extractCacheTags(ViewModel $viewModel)
 {
     if ($viewModel->getOption('esi') && !$viewModel->terminate()) {
         return;
     }
     $tags = (array) $viewModel->getOption(self::OPTION_CACHE_TAGS, []);
     $this->cacheTags = ArrayUtils::merge($this->cacheTags, $tags);
     if ($viewModel->hasChildren()) {
         foreach ($viewModel->getChildren() as $childViewModel) {
             $this->extractCacheTags($childViewModel);
         }
     }
 }
开发者ID:hummer2k,项目名称:convarnish,代码行数:17,代码来源:InjectTagsHeaderListener.php

示例2: testTerminationFlagIsMutable

 public function testTerminationFlagIsMutable()
 {
     $model = new ViewModel();
     $model->setTerminal(true);
     $this->assertTrue($model->terminate());
 }
开发者ID:haoyanfei,项目名称:zf2,代码行数:6,代码来源:ViewModelTest.php

示例3: renderAction

 /**
  * Render an action from a controller and render it's associated template
  * @param  string $expr
  * @param  array  $attributes
  * @param  array  $options
  * @return string
  */
 public function renderAction($expr, array $attributes, array $options)
 {
     ArgValidator::assert($expr, 'string');
     $serviceManager = Module::getServiceManager();
     $application = $serviceManager->get('Application');
     //parse the name of the controller, action and template directory that should be used
     if (strpos($expr, '/') > 0) {
         list($controllerName, $actionName) = explode('/', $expr);
         $templateDir = $controllerName . '/';
     } else {
         list($moduleName, $controllerName, $actionName) = explode(':', $expr);
         $actionName = lcfirst($actionName);
         $actionName = strtolower(preg_replace('/([A-Z])/', '-$1', $actionName));
         $templateDir = lcfirst($moduleName) . '/' . lcfirst($controllerName) . '/';
         $controllerName = $moduleName . '\\Controller\\' . $controllerName . 'Controller';
     }
     //instantiate the controller based on the given name
     $controller = $serviceManager->get('ControllerLoader')->get($controllerName);
     //clone the MvcEvent and route and update them with the provided parameters
     $event = $application->getMvcEvent();
     $routeMatch = clone $event->getRouteMatch();
     $event = clone $event;
     foreach ($attributes as $key => $value) {
         $routeMatch->setParam($key, $value);
     }
     $event->setRouteMatch($routeMatch);
     //inject the new event into the controller
     if ($controller instanceof InjectApplicationEventInterface) {
         $controller->setEvent($event);
     }
     //test if the action exists in the controller and change it to not-found if missing
     $method = AbstractActionController::getMethodFromAction($actionName);
     if (!method_exists($controller, $method)) {
         $method = 'notFoundAction';
         $actionName = 'not-found';
     }
     //call the method on the controller
     $response = $controller->{$method}();
     //if the result is an instance of the Response class return it
     if ($response instanceof Response) {
         return $response->getBody();
     }
     //if the response is an instance of ViewModel then render that one
     if ($response instanceof ModelInterface) {
         $viewModel = $response;
     } elseif ($response === null || is_array($response) || $response instanceof \ArrayAccess || $response instanceof \Traversable) {
         $viewModel = new ViewModel($response);
         $viewModel->setTemplate($templateDir . $actionName);
     } else {
         return '';
     }
     $viewModel->terminate();
     $viewModel->setOption('has_parent', true);
     $view = $serviceManager->get('Zend\\View\\View');
     $output = $view->render($viewModel);
     return $output;
 }
开发者ID:heartsentwined,项目名称:zf2-assetwig,代码行数:64,代码来源:Extension.php

示例4: canonizeErrorResult

 /**
  * Inspect the result for erroneous action of JSON/AJAX/Feed
  *
  * @param  MvcEvent $e
  * @return void
  */
 public function canonizeErrorResult(MvcEvent $e)
 {
     $result = $e->getResult();
     if ($result instanceof Response) {
         return;
     }
     if (!$this->type) {
         return;
     }
     $response = $e->getResponse();
     $statusCode = $response->getStatusCode();
     if ($statusCode < 400) {
         return;
     }
     // Cast controller view model to result ViewModel
     switch ($this->type) {
         // For Feed
         case 'feed':
             if ($result instanceof FeedModel) {
                 $model = $result;
                 $model->setTemplate('');
                 $model->clearChildren();
             } else {
                 $variables = array();
                 $options = array();
                 if ($result instanceof ViewModel) {
                     $variables = $result->getVariables();
                     $options = $result->getOptions();
                     $variables = (array) new FeedDataModel($variables);
                 } elseif ($result instanceof FeedDataModel) {
                     $variables = (array) $result;
                     $options = array('feed_type' => $result->getType());
                 }
                 $model = new FeedModel($variables, $options);
             }
             break;
             // For Json
         // For Json
         case 'json':
             if ($result instanceof JsonModel) {
                 $model = $result;
                 $model->setTemplate('');
                 $model->clearChildren();
             } else {
                 $variables = array();
                 $options = array();
                 if ($result instanceof ViewModel) {
                     $variables = $result->getVariables();
                     $options = $result->getOptions();
                 }
                 $model = new JsonModel($variables, $options);
             }
             break;
             // For AJAX/Flash
         // For AJAX/Flash
         case 'ajax':
             // MISC
         // MISC
         default:
             if ($result instanceof ViewModel) {
                 $model = $result;
                 $model->setTemplate('');
                 $model->clearChildren();
                 $result = null;
             } else {
                 $model = new ViewModel();
             }
             $model->terminate(true);
             break;
     }
     $e->setViewModel($model);
 }
开发者ID:Andyyang1981,项目名称:pi,代码行数:78,代码来源:ViewStrategyListener.php


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