Warning, file /webapps/ocs-webserver/library/Zend/Application/Resource/Translate.php was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Application
0017  * @subpackage Resource
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Application_Resource_ResourceAbstract
0025  */
0026 // require_once 'Zend/Application/Resource/ResourceAbstract.php';
0027 
0028 
0029 /**
0030  * Resource for setting translation options
0031  *
0032  * @uses       Zend_Application_Resource_ResourceAbstract
0033  * @category   Zend
0034  * @package    Zend_Application
0035  * @subpackage Resource
0036  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0037  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0038  */
0039 class Zend_Application_Resource_Translate extends Zend_Application_Resource_ResourceAbstract
0040 {
0041     const DEFAULT_REGISTRY_KEY = 'Zend_Translate';
0042 
0043     /**
0044      * @var Zend_Translate
0045      */
0046     protected $_translate;
0047 
0048     /**
0049      * Defined by Zend_Application_Resource_Resource
0050      *
0051      * @return Zend_Translate
0052      */
0053     public function init()
0054     {
0055         return $this->getTranslate();
0056     }
0057 
0058     /**
0059      * Retrieve translate object
0060      *
0061      * @return Zend_Translate
0062      * @throws Zend_Application_Resource_Exception if registry key was used
0063      *          already but is no instance of Zend_Translate
0064      */
0065     public function getTranslate()
0066     {
0067         if (null === $this->_translate) {
0068             $options = $this->getOptions();
0069 
0070             if (!isset($options['content']) && !isset($options['data'])) {
0071                 // require_once 'Zend/Application/Resource/Exception.php';
0072                 throw new Zend_Application_Resource_Exception('No translation source data provided.');
0073             } else if (array_key_exists('content', $options) && array_key_exists('data', $options)) {
0074                 // require_once 'Zend/Application/Resource/Exception.php';
0075                 throw new Zend_Application_Resource_Exception(
0076                     'Conflict on translation source data: choose only one key between content and data.'
0077                 );
0078             }
0079 
0080             if (empty($options['adapter'])) {
0081                 $options['adapter'] = Zend_Translate::AN_ARRAY;
0082             }
0083 
0084             if (!empty($options['data'])) {
0085                 $options['content'] = $options['data'];
0086                 unset($options['data']);
0087             }
0088 
0089             if (isset($options['log'])) {
0090                 if (is_array($options['log'])) {
0091                     $options['log'] = Zend_Log::factory($options['log']);
0092                 }
0093             }
0094 
0095             if (isset($options['options'])) {
0096                 foreach ($options['options'] as $key => $value) {
0097                     $options[$key] = $value;
0098                 }
0099             }
0100 
0101             if (!empty($options['cache']) && is_string($options['cache'])) {
0102                 $bootstrap = $this->getBootstrap();
0103                 if ($bootstrap instanceof Zend_Application_Bootstrap_ResourceBootstrapper &&
0104                     $bootstrap->hasPluginResource('CacheManager')
0105                 ) {
0106                     $cacheManager = $bootstrap->bootstrap('CacheManager')
0107                         ->getResource('CacheManager');
0108                     if (null !== $cacheManager &&
0109                         $cacheManager->hasCache($options['cache'])
0110                     ) {
0111                         $options['cache'] = $cacheManager->getCache($options['cache']);
0112                     }
0113                 }
0114             }
0115 
0116             $key = (isset($options['registry_key']) && !is_numeric($options['registry_key']))
0117                  ? $options['registry_key']
0118                  : self::DEFAULT_REGISTRY_KEY;
0119             unset($options['registry_key']);
0120 
0121             if (Zend_Registry::isRegistered($key)) {
0122                 $translate = Zend_Registry::get($key);
0123                 if (!$translate instanceof Zend_Translate) {
0124                     // require_once 'Zend/Application/Resource/Exception.php';
0125                     throw new Zend_Application_Resource_Exception(
0126                         $key
0127                         . ' already registered in registry but is '
0128                         . 'no instance of Zend_Translate'
0129                     );
0130                 }
0131 
0132                 $translate->addTranslation($options);
0133                 $this->_translate = $translate;
0134             } else {
0135                 $this->_translate = new Zend_Translate($options);
0136                 Zend_Registry::set($key, $this->_translate);
0137             }
0138         }
0139 
0140         return $this->_translate;
0141     }
0142 }