Added the zend framework 2 library, the path is specified in line no.26 in zend_modul...
[openemr.git] / interface / modules / zend_modules / library / Zend / Mvc / View / Console / DefaultRenderingStrategy.php
blob4fd597f4d0dbd41ddfa18aa18ec0a7282c36eb77
1 <?php
2 /**
3 * Zend Framework (http://framework.zend.com/)
5 * @link http://github.com/zendframework/zf2 for the canonical source repository
6 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
7 * @license http://framework.zend.com/license/new-bsd New BSD License
8 */
10 namespace Zend\Mvc\View\Console;
12 use Zend\Console\Response as ConsoleResponse;
13 use Zend\EventManager\AbstractListenerAggregate;
14 use Zend\EventManager\EventManagerInterface;
15 use Zend\EventManager\ListenerAggregateInterface;
16 use Zend\Mvc\MvcEvent;
17 use Zend\Stdlib\ResponseInterface as Response;
18 use Zend\View\Model\ConsoleModel as ConsoleViewModel;
20 class DefaultRenderingStrategy extends AbstractListenerAggregate
22 /**
23 * {@inheritDoc}
25 public function attach(EventManagerInterface $events)
27 $this->listeners[] = $events->attach(MvcEvent::EVENT_RENDER, array($this, 'render'), -10000);
30 /**
31 * Render the view
33 * @param MvcEvent $e
34 * @return Response
36 public function render(MvcEvent $e)
38 $result = $e->getResult();
39 if ($result instanceof Response) {
40 return $result; // the result is already rendered ...
43 // marshal arguments
44 $response = $e->getResponse();
46 if (empty($result)) {
47 // There is absolutely no result, so there's nothing to display.
48 // We will return an empty response object
49 return $response;
52 // Collect results from child models
53 $responseText = '';
54 if ($result->hasChildren()) {
55 foreach ($result->getChildren() as $child) {
56 // Do not use ::getResult() method here as we cannot be sure if
57 // children are also console models.
58 $responseText .= $child->getVariable(ConsoleViewModel::RESULT);
62 // Fetch result from primary model
63 if ($result instanceof ConsoleViewModel) {
64 $responseText .= $result->getResult();
65 } else {
66 $responseText .= $result->getVariable(ConsoleViewModel::RESULT);
69 // Append console response to response object
70 $response->setContent(
71 $response->getContent() . $responseText
74 // Pass on console-specific options
75 if ($response instanceof ConsoleResponse
76 && $result instanceof ConsoleViewModel
77 ) {
78 $errorLevel = $result->getErrorLevel();
79 $response->setErrorLevel($errorLevel);
82 return $response;