web/lib/Zend/Translate/Adapter.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Translate
    16  * @package    Zend_Translate
    17  * @subpackage Zend_Translate_Adapter
    17  * @subpackage Zend_Translate_Adapter
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    20  * @version    $Id: Adapter.php 22726 2010-07-30 10:52:07Z thomas $
    20  * @version    $Id: Adapter.php 24593 2012-01-05 20:35:02Z matthew $
    21  */
    21  */
    22 
    22 
    23 /**
    23 /**
    24  * @see Zend_Locale
    24  * @see Zend_Locale
    25  */
    25  */
    34  * Basic adapter class for each translation source adapter
    34  * Basic adapter class for each translation source adapter
    35  *
    35  *
    36  * @category   Zend
    36  * @category   Zend
    37  * @package    Zend_Translate
    37  * @package    Zend_Translate
    38  * @subpackage Zend_Translate_Adapter
    38  * @subpackage Zend_Translate_Adapter
    39  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    39  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    40  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    40  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    41  */
    41  */
    42 abstract class Zend_Translate_Adapter {
    42 abstract class Zend_Translate_Adapter {
    43     /**
    43     /**
    44      * Shows if locale detection is in automatic level
    44      * Shows if locale detection is in automatic level
   210                 $options = array_merge($opt, $options);
   210                 $options = array_merge($opt, $options);
   211             }
   211             }
   212         } else if (!is_array($options)) {
   212         } else if (!is_array($options)) {
   213             $options = array('content' => $options);
   213             $options = array('content' => $options);
   214         }
   214         }
       
   215         
       
   216         if (!isset($options['content']) || empty($options['content'])) {
       
   217             require_once 'Zend/Translate/Exception.php';
       
   218             throw new Zend_Translate_Exception("Required option 'content' is missing");
       
   219         }
   215 
   220 
   216         $originate = null;
   221         $originate = null;
   217         if (!empty($options['locale'])) {
   222         if (!empty($options['locale'])) {
   218             $originate = (string) $options['locale'];
   223             $originate = (string) $options['locale'];
   219         }
   224         }
   238 
   243 
   239         $options  = $options + $this->_options;
   244         $options  = $options + $this->_options;
   240         if (is_string($options['content']) and is_dir($options['content'])) {
   245         if (is_string($options['content']) and is_dir($options['content'])) {
   241             $options['content'] = realpath($options['content']);
   246             $options['content'] = realpath($options['content']);
   242             $prev = '';
   247             $prev = '';
   243             foreach (new RecursiveIteratorIterator(
   248             $iterator = new RecursiveIteratorIterator(
   244                      new RecursiveDirectoryIterator($options['content'], RecursiveDirectoryIterator::KEY_AS_PATHNAME),
   249                 new RecursiveRegexIterator(
   245                      RecursiveIteratorIterator::SELF_FIRST) as $directory => $info) {
   250                     new RecursiveDirectoryIterator($options['content'], RecursiveDirectoryIterator::KEY_AS_PATHNAME),
       
   251                     '/^(?!.*(\.svn|\.cvs)).*$/', RecursiveRegexIterator::MATCH
       
   252                 ),
       
   253                 RecursiveIteratorIterator::SELF_FIRST
       
   254             );
       
   255             
       
   256             foreach ($iterator as $directory => $info) {
   246                 $file = $info->getFilename();
   257                 $file = $info->getFilename();
   247                 if (is_array($options['ignore'])) {
   258                 if (is_array($options['ignore'])) {
   248                     foreach ($options['ignore'] as $key => $ignore) {
   259                     foreach ($options['ignore'] as $key => $ignore) {
   249                         if (strpos($key, 'regex') !== false) {
   260                         if (strpos($key, 'regex') !== false) {
   250                             if (preg_match($ignore, $directory)) {
   261                             if (preg_match($ignore, $directory)) {
   308                     } catch (Zend_Translate_Exception $e) {
   319                     } catch (Zend_Translate_Exception $e) {
   309                         // ignore failed sources while scanning
   320                         // ignore failed sources while scanning
   310                     }
   321                     }
   311                 }
   322                 }
   312             }
   323             }
       
   324             
       
   325             unset($iterator);
   313         } else {
   326         } else {
   314             $this->_addTranslationData($options);
   327             $this->_addTranslationData($options);
   315         }
   328         }
   316 
   329 
   317         if ((isset($this->_translate[$originate]) === true) and (count($this->_translate[$originate]) > 0)) {
   330         if ((isset($this->_translate[$originate]) === true) and (count($this->_translate[$originate]) > 0)) {
   462     }
   475     }
   463 
   476 
   464     /**
   477     /**
   465      * Returns the available languages from this adapter
   478      * Returns the available languages from this adapter
   466      *
   479      *
   467      * @return array
   480      * @return array|null
   468      */
   481      */
   469     public function getList()
   482     public function getList()
   470     {
   483     {
   471         $list = array_keys($this->_translate);
   484         $list = array_keys($this->_translate);
   472         $result = null;
   485         $result = null;