⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 data.php

📁 Bug tracker, and reporter.
💻 PHP
📖 第 1 页 / 共 4 页
字号:
<?php/** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category   Zend * @package    Zend_Locale * @subpackage Data * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @version    $Id: Data.php 8064 2008-02-16 10:58:39Z thomas $ * @license    http://framework.zend.com/license/new-bsd     New BSD License *//** * include needed classes */require_once 'Zend/Locale.php';/** * @category   Zend * @package    Zend_Locale * @subpackage Data * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com) * @license    http://framework.zend.com/license/new-bsd     New BSD License */class Zend_Locale_Data{    /**     * locale files     *     * @var ressource     * @access private     */    private static $_ldml = array();    /**     * list of values which are collected     *     * @var array     * @access private     */    private static $_list = array();    /**     * internal cache for ldml values     *      * @var Zend_Cache_Core     * @access private     */    private static $_cache = null;    /**     * Read the content from locale     *     * Can be called like:     * <ldml>     *     <delimiter>test</delimiter>     *     <second type='myone'>content</second>     *     <second type='mysecond'>content2</second>     *     <third type='mythird' />     * </ldml>     *     * Case 1: _readFile('ar','/ldml/delimiter')             -> returns [] = test     * Case 1: _readFile('ar','/ldml/second[@type=myone]')   -> returns [] = content     * Case 2: _readFile('ar','/ldml/second','type')         -> returns [myone] = content; [mysecond] = content2     * Case 3: _readFile('ar','/ldml/delimiter',,'right')    -> returns [right] = test     * Case 4: _readFile('ar','/ldml/third','type','myone')  -> returns [myone] = mythird     *     * @param  string $locale     * @param  string $path     * @param  string $attribute     * @param  string $value     * @access private     * @return array     */    private static function _readFile($locale, $path, $attribute, $value, $temp)    {        // without attribute - read all values        // with attribute    - read only this value        if (!empty(self::$_ldml[(string) $locale])) {            $result = self::$_ldml[(string) $locale]->xpath($path);            if (!empty($result)) {                foreach ($result as &$found) {                    if (empty($value)) {                        if (empty($attribute)) {                            // Case 1                            $temp[] = (string) $found;                        } else if (empty($temp[(string) $found[$attribute]])){                            // Case 2                            $temp[(string) $found[$attribute]] = (string) $found;                        }                    } else if (empty ($temp[$value])) {                        if (empty($attribute)) {                            // Case 3                            $temp[$value] = (string) $found;                        } else {                            // Case 4                            $temp[$value] = (string) $found[$attribute];                        }                    }                }            }        }        return $temp;    }    /**     * Find possible routing to other path or locale     *     * @param  string $locale     * @param  string $path     * @param  string $attribute     * @param  string $value     * @param  array  $temp     * @throws Zend_Locale_Exception     * @access private     */    private static function _findRoute($locale, $path, $attribute, $value, &$temp)    {        // load locale file if not already in cache        // needed for alias tag when referring to other locale        if (empty(self::$_ldml[(string) $locale])) {            $filename = dirname(__FILE__) . '/Data/' . $locale . '.xml';            if (!file_exists($filename)) {                require_once 'Zend/Locale/Exception.php';                throw new Zend_Locale_Exception("Missing locale file '$filename' for '$locale' locale.");            }            self::$_ldml[(string) $locale] = simplexml_load_file($filename);        }        // search for 'alias' tag in the search path for redirection        $search = '';        $tok = strtok($path, '/');        // parse the complete path        if (!empty(self::$_ldml[(string) $locale])) {            while ($tok !== false) {                $search .=  '/' . $tok;                if (strpos($search, '[@') !== false) {                    while (strrpos($search, '[@') > strrpos($search, ']')) {                        $tok = strtok('/');                        if (empty($tok)) {                            $search .= '/';                        }                        $search = $search . '/' . $tok;                    }                }                $result = self::$_ldml[(string) $locale]->xpath($search . '/alias');                // alias found                if (!empty($result)) {                    $source = $result[0]['source'];                    $newpath = $result[0]['path'];                    // new path - path //ldml is to ignore                    if ($newpath != '//ldml') {                        // other path - parse to make real path                        while (substr($newpath,0,3) == '../') {                            $newpath = substr($newpath, 3);                            $search = substr($search, 0, strrpos($search, '/'));                        }                        // truncate ../ to realpath otherwise problems with alias                        $path = $search . '/' . $newpath;                        while (($tok = strtok('/'))!== false) {                            $path = $path . '/' . $tok;                        }                    }                    // reroute to other locale                    if ($source != 'locale') {                        $locale = $source;                    }                    $temp = self::_getFile($locale, $path, $attribute, $value, $temp);                    return false;                }                $tok = strtok('/');            }        }        return true;    }    /**     * Read the right LDML file     *     * @param  string $locale     * @param  string $path     * @param  string $attribute     * @param  string $value     * @access private     */    private static function _getFile($locale, $path, $attribute = false, $value = false, $temp = array())    {        $result = self::_findRoute($locale, $path, $attribute, $value, $temp);        if ($result) {            $temp = self::_readFile($locale, $path, $attribute, $value, $temp);        }        // parse required locales reversive        // example: when given zh_Hans_CN        // 1. -> zh_Hans_CN        // 2. -> zh_Hans        // 3. -> zh        // 4. -> root        if (($locale != 'root') && ($result)) {            $locale = substr($locale, 0, -strlen(strrchr($locale, '_')));            if (!empty($locale)) {                $temp = self::_getFile($locale, $path, $attribute, $value, $temp);            } else {                $temp = self::_getFile('root', $path, $attribute, $value, $temp);            }        }        return $temp;    }    /**     * Find the details for supplemental calendar datas     *     * @param  string $locale Locale for Detaildata     * @param  array  $list   List to search     * @return string         Key for Detaildata     */    private static function _calendarDetail($locale, $list)    {        $ret = "001";        foreach ($list as $key => $value) {            if (strpos($locale, '_') !== false) {                $locale = substr($locale, strpos($locale, '_') + 1);            }            if (strpos($key, $locale) !== false) {                $ret = $key;                break;            }        }        return $ret;    }    /**     * Internal function for checking the locale     *     * @param string|Zend_Locale $locale Locale to check     * @return string     */    private static function _checkLocale($locale)    {        if (empty($locale)) {            $locale = new Zend_Locale();        }        if ($locale instanceof Zend_Locale) {            $locale = $locale->toString();        }        if (!($locale = Zend_Locale::isLocale($locale))) {            require_once 'Zend/Locale/Exception.php';            throw new Zend_Locale_Exception("Locale ($locale) is a unknown locale");        }        return $locale;    }    /**     * Read the LDML file, get a array of multipath defined value     *     * @param  string $locale     * @param  string $path

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -