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
10 namespace Zend\Mvc\Router\Http
;
12 use Zend\I18n\Translator\Translator
;
13 use Zend\I18n\Translator\TranslatorAwareInterface
;
14 use Zend\Stdlib\RequestInterface
as Request
;
17 * Translator aware tree route stack.
19 class TranslatorAwareTreeRouteStack
extends TreeRouteStack
implements TranslatorAwareInterface
22 * Translator used for translatable segments.
26 protected $translator;
29 * Whether the translator is enabled.
33 protected $translatorEnabled = true;
36 * Translator text domain to use.
40 protected $translatorTextDomain = 'default';
43 * match(): defined by \Zend\Mvc\Router\RouteInterface
45 * @see \Zend\Mvc\Router\RouteInterface::match()
46 * @param Request $request
47 * @param integer|null $pathOffset
48 * @param array $options
49 * @return RouteMatch|null
51 public function match(Request
$request, $pathOffset = null, array $options = array())
53 if ($this->hasTranslator() && $this->isTranslatorEnabled() && !isset($options['translator'])) {
54 $options['translator'] = $this->getTranslator();
57 if (!isset($options['text_domain'])) {
58 $options['text_domain'] = $this->getTranslatorTextDomain();
61 return parent
::match($request, $pathOffset, $options);
65 * assemble(): defined by \Zend\Mvc\Router\RouteInterface interface.
67 * @see \Zend\Mvc\Router\RouteInterface::assemble()
68 * @param array $params
69 * @param array $options
71 * @throws Exception\InvalidArgumentException
72 * @throws Exception\RuntimeException
74 public function assemble(array $params = array(), array $options = array())
76 if ($this->hasTranslator() && $this->isTranslatorEnabled() && !isset($options['translator'])) {
77 $options['translator'] = $this->getTranslator();
80 if (!isset($options['text_domain'])) {
81 $options['text_domain'] = $this->getTranslatorTextDomain();
84 return parent
::assemble($params, $options);
88 * setTranslator(): defined by TranslatorAwareInterface.
90 * @see TranslatorAwareInterface::setTranslator()
91 * @param Translator $translator
92 * @param string $textDomain
93 * @return TreeRouteStack
95 public function setTranslator(Translator
$translator = null, $textDomain = null)
97 $this->translator
= $translator;
99 if ($textDomain !== null) {
100 $this->setTranslatorTextDomain($textDomain);
107 * getTranslator(): defined by TranslatorAwareInterface.
109 * @see TranslatorAwareInterface::getTranslator()
112 public function getTranslator()
114 return $this->translator
;
118 * hasTranslator(): defined by TranslatorAwareInterface.
120 * @see TranslatorAwareInterface::hasTranslator()
123 public function hasTranslator()
125 return $this->translator
!== null;
129 * setTranslatorEnabled(): defined by TranslatorAwareInterface.
131 * @see TranslatorAwareInterface::setTranslatorEnabled()
132 * @param bool $enabled
133 * @return TreeRouteStack
135 public function setTranslatorEnabled($enabled = true)
137 $this->translatorEnabled
= $enabled;
142 * isTranslatorEnabled(): defined by TranslatorAwareInterface.
144 * @see TranslatorAwareInterface::isTranslatorEnabled()
147 public function isTranslatorEnabled()
149 return $this->translatorEnabled
;
153 * setTranslatorTextDomain(): defined by TranslatorAwareInterface.
155 * @see TranslatorAwareInterface::setTranslatorTextDomain()
156 * @param string $textDomain
159 public function setTranslatorTextDomain($textDomain = 'default')
161 $this->translatorTextDomain
= $textDomain;
167 * getTranslatorTextDomain(): defined by TranslatorAwareInterface.
169 * @see TranslatorAwareInterface::getTranslatorTextDomain()
172 public function getTranslatorTextDomain()
174 return $this->translatorTextDomain
;