123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- namespace Cube\Application\Resource;
- use Cube\Translate as TranslateObject;
- class Translate extends AbstractResource
- {
-
- protected $_translate;
-
- public function init()
- {
- if (!($this->_translate instanceof TranslateObject)) {
- if (!array_key_exists('translate', $this->_options)) {
- throw new \RuntimeException("The 'translate' key in the configuration array must be set.");
- }
- $this->_translate = new TranslateObject();
- if (!array_key_exists('adapter', $this->_options['translate']) ||
- !array_key_exists('translations', $this->_options['translate'])
- ) {
- throw new \RuntimeException("The 'adapter' and 'translations' keys need to be set when configuring the translate object.");
- }
- $adapterClass = $this->_options['translate']['adapter'];
- if (!class_exists($adapterClass)) {
- throw new \RuntimeException(
- sprintf("Class %s doesn't exist", $adapterClass));
- }
-
- $adapter = new $adapterClass();
- foreach ($this->_options['translate']['translations'] as $translation) {
- $adapter->addTranslation($translation);
- }
- $this->_translate->setAdapter($adapter);
- }
- return $this->_translate;
- }
- }
|