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 / View / Strategy / PhpRendererStrategy.php
blob2a8db5d2b7b4269f5cf14333160758ab577b8766
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\View\Strategy;
12 use Zend\EventManager\AbstractListenerAggregate;
13 use Zend\EventManager\EventManagerInterface;
14 use Zend\View\Renderer\PhpRenderer;
15 use Zend\View\ViewEvent;
17 class PhpRendererStrategy extends AbstractListenerAggregate
19 /**
20 * Placeholders that may hold content
22 * @var array
24 protected $contentPlaceholders = array('article', 'content');
26 /**
27 * @var PhpRenderer
29 protected $renderer;
31 /**
32 * Constructor
34 * @param PhpRenderer $renderer
36 public function __construct(PhpRenderer $renderer)
38 $this->renderer = $renderer;
41 /**
42 * Retrieve the composed renderer
44 * @return PhpRenderer
46 public function getRenderer()
48 return $this->renderer;
51 /**
52 * Set list of possible content placeholders
54 * @param array $contentPlaceholders
55 * @return PhpRendererStrategy
57 public function setContentPlaceholders(array $contentPlaceholders)
59 $this->contentPlaceholders = $contentPlaceholders;
60 return $this;
63 /**
64 * Get list of possible content placeholders
66 * @return array
68 public function getContentPlaceholders()
70 return $this->contentPlaceholders;
73 /**
74 * {@inheritDoc}
76 public function attach(EventManagerInterface $events, $priority = 1)
78 $this->listeners[] = $events->attach(ViewEvent::EVENT_RENDERER, array($this, 'selectRenderer'), $priority);
79 $this->listeners[] = $events->attach(ViewEvent::EVENT_RESPONSE, array($this, 'injectResponse'), $priority);
82 /**
83 * Select the PhpRenderer; typically, this will be registered last or at
84 * low priority.
86 * @param ViewEvent $e
87 * @return PhpRenderer
89 public function selectRenderer(ViewEvent $e)
91 return $this->renderer;
94 /**
95 * Populate the response object from the View
97 * Populates the content of the response object from the view rendering
98 * results.
100 * @param ViewEvent $e
101 * @return void
103 public function injectResponse(ViewEvent $e)
105 $renderer = $e->getRenderer();
106 if ($renderer !== $this->renderer) {
107 return;
110 $result = $e->getResult();
111 $response = $e->getResponse();
113 // Set content
114 // If content is empty, check common placeholders to determine if they are
115 // populated, and set the content from them.
116 if (empty($result)) {
117 $placeholders = $renderer->plugin('placeholder');
118 foreach ($this->contentPlaceholders as $placeholder) {
119 if ($placeholders->containerExists($placeholder)) {
120 $result = (string) $placeholders->getContainer($placeholder);
121 break;
125 $response->setContent($result);