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 / Helper / HeadTitle.php
blob900ae5e146d96aa8651f3476e42f20b802069a04
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\Helper;
12 use Zend\I18n\Translator\Translator;
13 use Zend\I18n\Translator\TranslatorAwareInterface;
14 use Zend\View\Exception;
16 /**
17 * Helper for setting and retrieving title element for HTML head
19 class HeadTitle extends Placeholder\Container\AbstractStandalone implements
20 TranslatorAwareInterface
22 /**
23 * Registry key for placeholder
25 * @var string
27 protected $regKey = 'Zend_View_Helper_HeadTitle';
29 /**
30 * Default title rendering order (i.e. order in which each title attached)
32 * @var string
34 protected $defaultAttachOrder = null;
36 /**
37 * Translator (optional)
39 * @var Translator
41 protected $translator;
43 /**
44 * Translator text domain (optional)
46 * @var string
48 protected $translatorTextDomain = 'default';
50 /**
51 * Whether translator should be used
53 * @var bool
55 protected $translatorEnabled = true;
57 /**
58 * Retrieve placeholder for title element and optionally set state
60 * @param string $title
61 * @param string $setType
62 * @return HeadTitle
64 public function __invoke($title = null, $setType = null)
66 if (null === $setType) {
67 $setType = (null === $this->getDefaultAttachOrder())
68 ? Placeholder\Container\AbstractContainer::APPEND
69 : $this->getDefaultAttachOrder();
72 $title = (string) $title;
73 if ($title !== '') {
74 if ($setType == Placeholder\Container\AbstractContainer::SET) {
75 $this->set($title);
76 } elseif ($setType == Placeholder\Container\AbstractContainer::PREPEND) {
77 $this->prepend($title);
78 } else {
79 $this->append($title);
83 return $this;
86 /**
87 * Render title (wrapped by title tag)
89 * @param string|null $indent
90 * @return string
92 public function toString($indent = null)
94 $indent = (null !== $indent)
95 ? $this->getWhitespace($indent)
96 : $this->getIndent();
98 $output = $this->renderTitle();
100 return $indent . '<title>' . $output . '</title>';
104 * Render title string
106 * @return string
108 public function renderTitle()
110 $items = array();
112 if (null !== ($translator = $this->getTranslator())) {
113 foreach ($this as $item) {
114 $items[] = $translator->translate(
115 $item, $this->getTranslatorTextDomain()
118 } else {
119 foreach ($this as $item) {
120 $items[] = $item;
124 $separator = $this->getSeparator();
125 $output = '';
127 $prefix = $this->getPrefix();
128 if ($prefix) {
129 $output .= $prefix;
132 $output .= implode($separator, $items);
134 $postfix = $this->getPostfix();
135 if ($postfix) {
136 $output .= $postfix;
139 $output = ($this->autoEscape) ? $this->escape($output) : $output;
141 return $output;
145 * Set a default order to add titles
147 * @param string $setType
148 * @throws Exception\DomainException
149 * @return HeadTitle
151 public function setDefaultAttachOrder($setType)
153 if (!in_array($setType, array(
154 Placeholder\Container\AbstractContainer::APPEND,
155 Placeholder\Container\AbstractContainer::SET,
156 Placeholder\Container\AbstractContainer::PREPEND
157 ))) {
158 throw new Exception\DomainException(
159 "You must use a valid attach order: 'PREPEND', 'APPEND' or 'SET'"
162 $this->defaultAttachOrder = $setType;
164 return $this;
168 * Get the default attach order, if any.
170 * @return mixed
172 public function getDefaultAttachOrder()
174 return $this->defaultAttachOrder;
177 // Translator methods - Good candidate to refactor as a trait with PHP 5.4
180 * Sets translator to use in helper
182 * @param Translator $translator [optional] translator.
183 * Default is null, which sets no translator.
184 * @param string $textDomain [optional] text domain
185 * Default is null, which skips setTranslatorTextDomain
186 * @return HeadTitle
188 public function setTranslator(Translator $translator = null, $textDomain = null)
190 $this->translator = $translator;
191 if (null !== $textDomain) {
192 $this->setTranslatorTextDomain($textDomain);
194 return $this;
198 * Returns translator used in helper
200 * @return Translator|null
202 public function getTranslator()
204 if (! $this->isTranslatorEnabled()) {
205 return null;
208 return $this->translator;
212 * Checks if the helper has a translator
214 * @return bool
216 public function hasTranslator()
218 return (bool) $this->getTranslator();
222 * Sets whether translator is enabled and should be used
224 * @param bool $enabled [optional] whether translator should be used.
225 * Default is true.
226 * @return HeadTitle
228 public function setTranslatorEnabled($enabled = true)
230 $this->translatorEnabled = (bool) $enabled;
231 return $this;
235 * Returns whether translator is enabled and should be used
237 * @return bool
239 public function isTranslatorEnabled()
241 return $this->translatorEnabled;
245 * Set translation text domain
247 * @param string $textDomain
248 * @return HeadTitle
250 public function setTranslatorTextDomain($textDomain = 'default')
252 $this->translatorTextDomain = $textDomain;
253 return $this;
257 * Return the translation text domain
259 * @return string
261 public function getTranslatorTextDomain()
263 return $this->translatorTextDomain;