/** * Constructor * * @param array $options associative array of options * @throws IfwPsn_Vendor_Zend_Cache_Exception */ public function __construct(array $options = array()) { if (!function_exists('zend_shm_cache_store')) { IfwPsn_Vendor_Zend_Cache::throwException('IfwPsn_Vendor_Zend_Cache_ZendServer_ShMem backend has to be used within Zend Server environment.'); } parent::__construct($options); }
/** * Make a control key with the string containing datas * * @param string $data Data * @param string $controlType Type of control 'md5', 'crc32' or 'strlen' * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return string Control key */ protected function _hash($data, $controlType) { switch ($controlType) { case 'md5': return md5($data); case 'crc32': return crc32($data); case 'strlen': return strlen($data); case 'adler32': return hash('adler32', $data); default: IfwPsn_Vendor_Zend_Cache::throwException("Incorrect hash function : {$controlType}"); } }
/** * Log a message at the WARN (4) priority. * * @param string $message * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return void */ protected function _log($message, $priority = 4) { if (!$this->_options['logging']) { return; } if (!(isset($this->_options['logger']) || $this->_options['logger'] instanceof IfwPsn_Vendor_Zend_Log)) { IfwPsn_Vendor_Zend_Cache::throwException('Logging is enabled but logger is not set'); } $logger = $this->_options['logger']; $logger->log($message, $priority); }
/** * Clean some cache records * * Available modes are : * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) * This mode is not supported in this backend * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags * ($tags can be an array of strings or a single string) * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => unsupported * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags * ($tags can be an array of strings or a single string) * * @param string $mode Clean mode * @param array $tags Array of tags * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return boolean True if no problem */ public function clean($mode = IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL, $tags = array()) { switch ($mode) { case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL: case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_OLD: $cache_dir = ini_get('zend_accelerator.output_cache_dir'); if (!$cache_dir) { return false; } $cache_dir .= '/.php_cache_api/'; return $this->_clean($cache_dir, $mode); break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_TAG: $idlist = null; foreach ($tags as $tag) { $next_idlist = output_cache_get(self::TAGS_PREFIX . $tag, $this->_directives['lifetime']); if ($idlist) { $idlist = array_intersect_assoc($idlist, $next_idlist); } else { $idlist = $next_idlist; } if (count($idlist) == 0) { // if ID list is already empty - we may skip checking other IDs $idlist = null; break; } } if ($idlist) { foreach ($idlist as $id) { output_cache_remove_key($id); } } return true; break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: $this->_log("IfwPsn_Vendor_Zend_Cache_Backend_ZendPlatform::clean() : CLEANING_MODE_NOT_MATCHING_TAG is not supported by the Zend Platform backend"); return false; break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: $idlist = null; foreach ($tags as $tag) { $next_idlist = output_cache_get(self::TAGS_PREFIX . $tag, $this->_directives['lifetime']); if ($idlist) { $idlist = array_merge_recursive($idlist, $next_idlist); } else { $idlist = $next_idlist; } if (count($idlist) == 0) { // if ID list is already empty - we may skip checking other IDs $idlist = null; break; } } if ($idlist) { foreach ($idlist as $id) { output_cache_remove_key($id); } } return true; break; default: IfwPsn_Vendor_Zend_Cache::throwException('Invalid mode for clean() method'); break; } }
/** * Clean some cache records * * Available modes are : * 'all' (default) => remove all cache entries ($tags is not used) * 'old' => unsupported * 'matchingTag' => unsupported * 'notMatchingTag' => unsupported * 'matchingAnyTag' => unsupported * * @param string $mode clean mode * @param array $tags array of tags * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return boolean true if no problem */ public function clean($mode = IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL, $tags = array()) { switch ($mode) { case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL: // Necessary because xcache_clear_cache() need basic authentification $backup = array(); if (isset($_SERVER['PHP_AUTH_USER'])) { $backup['PHP_AUTH_USER'] = $_SERVER['PHP_AUTH_USER']; } if (isset($_SERVER['PHP_AUTH_PW'])) { $backup['PHP_AUTH_PW'] = $_SERVER['PHP_AUTH_PW']; } if ($this->_options['user']) { $_SERVER['PHP_AUTH_USER'] = $this->_options['user']; } if ($this->_options['password']) { $_SERVER['PHP_AUTH_PW'] = $this->_options['password']; } $cnt = xcache_count(XC_TYPE_VAR); for ($i = 0; $i < $cnt; $i++) { xcache_clear_cache(XC_TYPE_VAR, $i); } if (isset($backup['PHP_AUTH_USER'])) { $_SERVER['PHP_AUTH_USER'] = $backup['PHP_AUTH_USER']; $_SERVER['PHP_AUTH_PW'] = $backup['PHP_AUTH_PW']; } return true; break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_OLD: $this->_log("IfwPsn_Vendor_Zend_Cache_Backend_Xcache::clean() : CLEANING_MODE_OLD is unsupported by the Xcache backend"); break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_TAG: case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: $this->_log(self::TAGS_UNSUPPORTED_BY_CLEAN_OF_XCACHE_BACKEND); break; default: IfwPsn_Vendor_Zend_Cache::throwException('Invalid mode for clean() method'); break; } }
/** * Return the filling percentage of the backend storage * * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return int integer between 0 and 100 */ public function getFillingPercentage() { $mems = $this->_memcache->getExtendedStats(); $memSize = null; $memUsed = null; foreach ($mems as $key => $mem) { if ($mem === false) { $this->_log('can\'t get stat from ' . $key); continue; } $eachSize = $mem['limit_maxbytes']; $eachUsed = $mem['bytes']; if ($eachUsed > $eachSize) { $eachUsed = $eachSize; } $memSize += $eachSize; $memUsed += $eachUsed; } if ($memSize === null || $memUsed === null) { IfwPsn_Vendor_Zend_Cache::throwException('Can\'t get filling percentage'); } return (int) (100.0 * ($memUsed / $memSize)); }
/** * Main method : call the specified method or get the result from cache * * @param string $name Method name * @param array $parameters Method parameters * @return mixed Result * @throws Exception */ public function __call($name, $parameters) { $callback = array($this->_cachedEntity, $name); if (!is_callable($callback, false)) { IfwPsn_Vendor_Zend_Cache::throwException('Invalid callback'); } $cacheBool1 = $this->_specificOptions['cache_by_default']; $cacheBool2 = in_array($name, $this->_specificOptions['cached_methods']); $cacheBool3 = in_array($name, $this->_specificOptions['non_cached_methods']); $cache = ($cacheBool1 || $cacheBool2) && !$cacheBool3; if (!$cache) { // We do not have not cache return call_user_func_array($callback, $parameters); } $id = $this->makeId($name, $parameters); if (($rs = $this->load($id)) && array_key_exists(0, $rs) && array_key_exists(1, $rs)) { // A cache is available $output = $rs[0]; $return = $rs[1]; } else { // A cache is not available (or not valid for this frontend) ob_start(); ob_implicit_flush(false); try { $return = call_user_func_array($callback, $parameters); $output = ob_get_clean(); $data = array($output, $return); $this->save($data, $id, $this->_tags, $this->_specificLifetime, $this->_priority); } catch (Exception $e) { ob_end_clean(); throw $e; } } echo $output; return $return; }
/** * Change the master_files option * * @param array $masterFiles the complete paths and name of the master files */ public function setMasterFiles(array $masterFiles) { $this->_specificOptions['master_file'] = null; // to keep a compatibility $this->_specificOptions['master_files'] = null; $this->_masterFile_mtimes = array(); clearstatcache(); $i = 0; foreach ($masterFiles as $masterFile) { if (file_exists($masterFile)) { $mtime = filemtime($masterFile); } else { $mtime = false; } if (!$this->_specificOptions['ignore_missing_master_files'] && !$mtime) { IfwPsn_Vendor_Zend_Cache::throwException('Unable to read master_file : ' . $masterFile); } $this->_masterFile_mtimes[$i] = $mtime; $this->_specificOptions['master_files'][$i] = $masterFile; if ($i === 0) { // to keep a compatibility $this->_specificOptions['master_file'] = $masterFile; } $i++; } }
/** * Fetch the named cache object, or instantiate and return a cache object * using a named configuration template * * @param string $name * @return IfwPsn_Vendor_Zend_Cache_Core */ public function getCache($name) { if (isset($this->_caches[$name])) { return $this->_caches[$name]; } if (isset($this->_optionTemplates[$name])) { if ($name == self::PAGECACHE && (!isset($this->_optionTemplates[$name]['backend']['options']['tag_cache']) || !$this->_optionTemplates[$name]['backend']['options']['tag_cache'] instanceof IfwPsn_Vendor_Zend_Cache_Core)) { $this->_optionTemplates[$name]['backend']['options']['tag_cache'] = $this->getCache(self::PAGETAGCACHE); } $this->_caches[$name] = IfwPsn_Vendor_Zend_Cache::factory($this->_optionTemplates[$name]['frontend']['name'], $this->_optionTemplates[$name]['backend']['name'], isset($this->_optionTemplates[$name]['frontend']['options']) ? $this->_optionTemplates[$name]['frontend']['options'] : array(), isset($this->_optionTemplates[$name]['backend']['options']) ? $this->_optionTemplates[$name]['backend']['options'] : array(), isset($this->_optionTemplates[$name]['frontend']['customFrontendNaming']) ? $this->_optionTemplates[$name]['frontend']['customFrontendNaming'] : false, isset($this->_optionTemplates[$name]['backend']['customBackendNaming']) ? $this->_optionTemplates[$name]['backend']['customBackendNaming'] : false, isset($this->_optionTemplates[$name]['frontendBackendAutoload']) ? $this->_optionTemplates[$name]['frontendBackendAutoload'] : false); return $this->_caches[$name]; } }
/** * Return the filling percentage of the backend storage * * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return int integer between 0 and 100 */ public function getFillingPercentage() { $mem = apc_sma_info(true); $memSize = $mem['num_seg'] * $mem['seg_size']; $memAvailable = $mem['avail_mem']; $memUsed = $memSize - $memAvailable; if ($memSize == 0) { IfwPsn_Vendor_Zend_Cache::throwException('can\'t get apc memory size'); } if ($memUsed > $memSize) { return 100; } return (int) (100.0 * ($memUsed / $memSize)); }
/** * Clean some cache records * * Available modes are : * 'all' (default) => remove all cache entries ($tags is not used) * 'old' => unsupported * 'matchingTag' => unsupported * 'notMatchingTag' => unsupported * 'matchingAnyTag' => unsupported * * @param string $mode clean mode * @param array $tags array of tags * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return boolean true if no problem */ public function clean($mode = IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL, $tags = array()) { switch ($mode) { case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL: $this->_clear(); return true; break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_OLD: $this->_log("IfwPsn_Vendor_Zend_Cache_Backend_ZendServer::clean() : CLEANING_MODE_OLD is unsupported by the Zend Server backends."); break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_TAG: case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: $this->_clear(); $this->_log('IfwPsn_Vendor_Zend_Cache_Backend_ZendServer::clean() : tags are unsupported by the Zend Server backends.'); break; default: IfwPsn_Vendor_Zend_Cache::throwException('Invalid mode for clean() method'); break; } }
/** * Make a cache id from the function name and parameters * * @param callback $callback A valid callback * @param array $args Function parameters * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return string Cache id */ public function makeId($callback, array $args = array()) { if (!is_callable($callback, true, $name)) { IfwPsn_Vendor_Zend_Cache::throwException('Invalid callback'); } // functions, methods and classnames are case-insensitive $name = strtolower($name); // generate a unique id for object callbacks if (is_object($callback)) { // Closures & __invoke $object = $callback; } elseif (isset($callback[0])) { // array($object, 'method') $object = $callback[0]; } if (isset($object)) { try { $tmp = @serialize($callback); } catch (Exception $e) { IfwPsn_Vendor_Zend_Cache::throwException($e->getMessage()); } if (!$tmp) { $lastErr = error_get_last(); IfwPsn_Vendor_Zend_Cache::throwException("Can't serialize callback object to generate id: {$lastErr['message']}"); } $name .= '__' . $tmp; } // generate a unique id for arguments $argsStr = ''; if ($args) { try { $argsStr = @serialize(array_values($args)); } catch (Exception $e) { IfwPsn_Vendor_Zend_Cache::throwException($e->getMessage()); } if (!$argsStr) { $lastErr = error_get_last(); throw IfwPsn_Vendor_Zend_Cache::throwException("Can't serialize arguments to generate id: {$lastErr['message']}"); } } return md5($name . $argsStr); }
/** * Log a message at the WARN (4) priority. * * @param string $message * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return void */ protected function _log($message, $priority = 4) { if (!$this->_directives['logging']) { return; } if (!isset($this->_directives['logger'])) { IfwPsn_Vendor_Zend_Cache::throwException('Logging is enabled but logger is not set.'); } $logger = $this->_directives['logger']; if (!$logger instanceof IfwPsn_Vendor_Zend_Log) { IfwPsn_Vendor_Zend_Cache::throwException('Logger object is not an instance of IfwPsn_Vendor_Zend_Log class.'); } $logger->log($message, $priority); }
/** * Specific setter for the 'regexps' option (with some additional tests) * * @param array $options Associative array * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return void */ protected function _setRegexps($regexps) { if (!is_array($regexps)) { IfwPsn_Vendor_Zend_Cache::throwException('regexps option must be an array !'); } foreach ($regexps as $regexp => $conf) { if (!is_array($conf)) { IfwPsn_Vendor_Zend_Cache::throwException('regexps option must be an array of arrays !'); } $validKeys = array_keys($this->_specificOptions['default_options']); foreach ($conf as $key => $value) { if (!is_string($key)) { IfwPsn_Vendor_Zend_Cache::throwException("unknown option [{$key}] !"); } $key = strtolower($key); if (!in_array($key, $validKeys)) { unset($regexps[$regexp][$key]); } } } $this->setOption('regexps', $regexps); }
/** * Frontend Constructor * * @param string $frontend * @param array $frontendOptions * @param boolean $customFrontendNaming * @param boolean $autoload * @return IfwPsn_Vendor_Zend_Cache_Core|IfwPsn_Vendor_Zend_Cache_Frontend */ public static function _makeFrontend($frontend, $frontendOptions = array(), $customFrontendNaming = false, $autoload = false) { if (!$customFrontendNaming) { $frontend = self::_normalizeName($frontend); } if (in_array($frontend, self::$standardFrontends)) { // we use a standard frontend // For perfs reasons, with frontend == 'Core', we can interact with the Core itself $frontendClass = 'IfwPsn_Vendor_Zend_Cache_' . ($frontend != 'Core' ? 'Frontend_' : '') . $frontend; // security controls are explicit require_once IFW_PSN_LIB_ROOT . str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php'; } else { // we use a custom frontend if (!preg_match('~^[\\w\\\\]+$~D', $frontend)) { IfwPsn_Vendor_Zend_Cache::throwException("Invalid frontend name [{$frontend}]"); } if (!$customFrontendNaming) { // we use this boolean to avoid an API break $frontendClass = 'IfwPsn_Vendor_Zend_Cache_Frontend_' . $frontend; } else { $frontendClass = $frontend; } if (!$autoload) { $file = str_replace('_', DIRECTORY_SEPARATOR, $frontendClass) . '.php'; if (!self::_isReadable($file)) { self::throwException("file {$file} not found in include_path"); } require_once $file; } } return new $frontendClass($frontendOptions); }
/** * Validate a cache id or a tag (security, reliable filenames, reserved prefixes...) * * Throw an exception if a problem is found * * @param string $string Cache id or tag * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return void * @deprecated Not usable until perhaps ZF 2.0 */ protected static function _validateIdOrTag($string) { if (!is_string($string)) { IfwPsn_Vendor_Zend_Cache::throwException('Invalid id or tag : must be a string'); } // Internal only checked in Frontend - not here! if (substr($string, 0, 9) == 'internal-') { return; } // Validation assumes no query string, fragments or scheme included - only the path if (!preg_match('/^(?:\\/(?:(?:%[[:xdigit:]]{2}|[A-Za-z0-9-_.!~*\'()\\[\\]:@&=+$,;])*)?)+$/', $string)) { IfwPsn_Vendor_Zend_Cache::throwException("Invalid id or tag '{$string}' : must be a valid URL path"); } }
/** * Check if the database structure is ok (with the good version), if no : build it * * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return boolean True if ok */ private function _checkAndBuildStructure() { if (!$this->_structureChecked) { if (!$this->_checkStructureVersion()) { $this->_buildStructure(); if (!$this->_checkStructureVersion()) { IfwPsn_Vendor_Zend_Cache::throwException("Impossible to build cache structure in " . $this->_options['cache_db_complete_path']); } } $this->_structureChecked = true; } return true; }
/** * Stop the cache * * @param array $tags Tags array * @param int $specificLifetime If != false, set a specific lifetime for this cache record (null => infinite lifetime) * @param string $forcedDatas If not null, force written datas with this * @param boolean $echoData If set to true, datas are sent to the browser * @param int $priority integer between 0 (very low priority) and 10 (maximum priority) used by some particular backends * @return void */ public function end($tags = array(), $specificLifetime = false, $forcedDatas = null, $echoData = true, $priority = 8) { if ($forcedDatas === null) { $data = ob_get_clean(); } else { $data =& $forcedDatas; } $id = array_pop($this->_idStack); if ($id === null) { IfwPsn_Vendor_Zend_Cache::throwException('use of end() without a start()'); } $this->save($data, $id, $tags, $specificLifetime, $priority); if ($echoData) { echo $data; } }
/** * Read the LDML file, get a single path defined value * * @param string $locale * @param string $path * @param string $value * @return string * @access public */ public static function getContent($locale, $path, $value = false) { $locale = self::_checkLocale($locale); if (!isset(self::$_cache) && !self::$_cacheDisabled) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Cache.php'; self::$_cache = IfwPsn_Vendor_Zend_Cache::factory('Core', 'File', array('automatic_serialization' => true), array()); } $val = $value; if (is_array($value)) { $val = implode('_', $value); } $val = urlencode($val); $id = strtr('IfwPsn_Vendor_Zend_LocaleC_' . $locale . '_' . $path . '_' . $val, array('-' => '_', '%' => '_', '+' => '_')); if (!self::$_cacheDisabled && ($result = self::$_cache->load($id))) { return unserialize($result); } switch (strtolower($path)) { case 'language': $temp = self::_getFile($locale, '/ldml/localeDisplayNames/languages/language[@type=\'' . $value . '\']', 'type'); break; case 'script': $temp = self::_getFile($locale, '/ldml/localeDisplayNames/scripts/script[@type=\'' . $value . '\']', 'type'); break; case 'country': case 'territory': $temp = self::_getFile($locale, '/ldml/localeDisplayNames/territories/territory[@type=\'' . $value . '\']', 'type'); break; case 'variant': $temp = self::_getFile($locale, '/ldml/localeDisplayNames/variants/variant[@type=\'' . $value . '\']', 'type'); break; case 'key': $temp = self::_getFile($locale, '/ldml/localeDisplayNames/keys/key[@type=\'' . $value . '\']', 'type'); break; case 'defaultcalendar': $givenLocale = new IfwPsn_Vendor_Zend_Locale($locale); $territory = $givenLocale->getRegion(); unset($givenLocale); $temp = self::_getFile('supplementalData', '/supplementalData/calendarPreferenceData/calendarPreference[contains(@territories,\'' . $territory . '\')]', 'ordering', 'ordering'); if (isset($temp['ordering'])) { list($temp) = explode(' ', $temp['ordering']); } else { $temp = 'gregorian'; } break; case 'monthcontext': /* default context is always 'format' if (empty ($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/default', 'choice', 'context'); */ $temp = 'format'; break; case 'defaultmonth': /* default width is always 'wide' if (empty ($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/default', 'choice', 'default'); */ $temp = 'wide'; break; case 'month': if (!is_array($value)) { $temp = $value; $value = array("gregorian", "format", "wide", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/months/monthContext[@type=\'' . $value[1] . '\']/monthWidth[@type=\'' . $value[2] . '\']/month[@type=\'' . $value[3] . '\']', 'type'); break; case 'daycontext': /* default context is always 'format' if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/default', 'choice', 'context'); */ $temp = 'format'; break; case 'defaultday': /* default width is always 'wide' if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/default', 'choice', 'default'); */ $temp = 'wide'; break; case 'day': if (!is_array($value)) { $temp = $value; $value = array("gregorian", "format", "wide", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/days/dayContext[@type=\'' . $value[1] . '\']/dayWidth[@type=\'' . $value[2] . '\']/day[@type=\'' . $value[3] . '\']', 'type'); break; case 'quarter': if (!is_array($value)) { $temp = $value; $value = array("gregorian", "format", "wide", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/quarters/quarterContext[@type=\'' . $value[1] . '\']/quarterWidth[@type=\'' . $value[2] . '\']/quarter[@type=\'' . $value[3] . '\']', 'type'); break; case 'am': if (empty($value)) { $value = array("gregorian", "format", "wide"); } if (!is_array($value)) { $temp = $value; $value = array($temp, "format", "wide"); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dayPeriods/dayPeriodContext[@type=\'' . $value[1] . '\']/dayPeriodWidth[@type=\'' . $value[2] . '\']/dayPeriod[@type=\'am\']', '', 'dayPeriod'); break; case 'pm': if (empty($value)) { $value = array("gregorian", "format", "wide"); } if (!is_array($value)) { $temp = $value; $value = array($temp, "format", "wide"); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dayPeriods/dayPeriodContext[@type=\'' . $value[1] . '\']/dayPeriodWidth[@type=\'' . $value[2] . '\']/dayPeriod[@type=\'pm\']', '', 'dayPeriod'); break; case 'era': if (!is_array($value)) { $temp = $value; $value = array("gregorian", "Abbr", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/eras/era' . $value[1] . '/era[@type=\'' . $value[2] . '\']', 'type'); break; case 'defaultdate': /* default choice is deprecated in CDLR - should be always medium here if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/default', 'choice', 'default'); */ $temp = 'medium'; break; case 'date': if (empty($value)) { $value = array("gregorian", "medium"); } if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateFormats/dateFormatLength[@type=\'' . $value[1] . '\']/dateFormat/pattern', '', 'pattern'); break; case 'defaulttime': /* default choice is deprecated in CDLR - should be always medium here if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/default', 'choice', 'default'); */ $temp = 'medium'; break; case 'time': if (empty($value)) { $value = array("gregorian", "medium"); } if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/timeFormats/timeFormatLength[@type=\'' . $value[1] . '\']/timeFormat/pattern', '', 'pattern'); break; case 'datetime': if (empty($value)) { $value = array("gregorian", "medium"); } if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $date = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateFormats/dateFormatLength[@type=\'' . $value[1] . '\']/dateFormat/pattern', '', 'pattern'); $time = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/timeFormats/timeFormatLength[@type=\'' . $value[1] . '\']/timeFormat/pattern', '', 'pattern'); $datetime = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateTimeFormats/dateTimeFormatLength[@type=\'' . $value[1] . '\']/dateTimeFormat/pattern', '', 'pattern'); $temp = str_replace(array('{0}', '{1}'), array(current($time), current($date)), current($datetime)); break; case 'dateitem': if (empty($value)) { $value = array("gregorian", "yyMMdd"); } if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateTimeFormats/availableFormats/dateFormatItem[@id=\'' . $value[1] . '\']', ''); break; case 'dateinterval': if (empty($value)) { $value = array("gregorian", "yMd", "y"); } if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp, $temp[0]); } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/dateTimeFormats/intervalFormats/intervalFormatItem[@id=\'' . $value[1] . '\']/greatestDifference[@id=\'' . $value[2] . '\']', ''); break; case 'field': if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $temp = self::_getFile($locale, '/ldml/dates/fields/field[@type=\'' . $value[1] . '\']/displayName', '', $value[1]); break; case 'relative': if (!is_array($value)) { $temp = $value; $value = array("gregorian", $temp); } $temp = self::_getFile($locale, '/ldml/dates/fields/field[@type=\'day\']/relative[@type=\'' . $value[1] . '\']', '', $value[1]); // $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value[0] . '\']/fields/field/relative[@type=\'' . $value[1] . '\']', '', $value[1]); break; case 'defaultnumberingsystem': $temp = self::_getFile($locale, '/ldml/numbers/defaultNumberingSystem', '', 'default'); break; case 'decimalnumber': $temp = self::_getFile($locale, '/ldml/numbers/decimalFormats/decimalFormatLength/decimalFormat/pattern', '', 'default'); break; case 'scientificnumber': $temp = self::_getFile($locale, '/ldml/numbers/scientificFormats/scientificFormatLength/scientificFormat/pattern', '', 'default'); break; case 'percentnumber': $temp = self::_getFile($locale, '/ldml/numbers/percentFormats/percentFormatLength/percentFormat/pattern', '', 'default'); break; case 'currencynumber': $temp = self::_getFile($locale, '/ldml/numbers/currencyFormats/currencyFormatLength/currencyFormat/pattern', '', 'default'); break; case 'nametocurrency': $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value); break; case 'currencytoname': $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/displayName', '', $value); $_temp = self::_getFile($locale, '/ldml/numbers/currencies/currency', 'type'); $temp = array(); foreach ($_temp as $key => $keyvalue) { $val = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $key . '\']/displayName', '', $key); if (!isset($val[$key]) or $val[$key] != $value) { continue; } if (!isset($temp[$val[$key]])) { $temp[$val[$key]] = $key; } else { $temp[$val[$key]] .= " " . $key; } } break; case 'currencysymbol': $temp = self::_getFile($locale, '/ldml/numbers/currencies/currency[@type=\'' . $value . '\']/symbol', '', $value); break; case 'question': $temp = self::_getFile($locale, '/ldml/posix/messages/' . $value . 'str', '', $value); break; case 'currencyfraction': if (empty($value)) { $value = "DEFAULT"; } $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'digits', 'digits'); break; case 'currencyrounding': if (empty($value)) { $value = "DEFAULT"; } $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/fractions/info[@iso4217=\'' . $value . '\']', 'rounding', 'rounding'); break; case 'currencytoregion': $temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $value . '\']/currency', 'iso4217', $value); break; case 'regiontocurrency': $_temp = self::_getFile('supplementalData', '/supplementalData/currencyData/region', 'iso3166'); $temp = array(); foreach ($_temp as $key => $keyvalue) { $val = self::_getFile('supplementalData', '/supplementalData/currencyData/region[@iso3166=\'' . $key . '\']/currency', 'iso4217', $key); if (!isset($val[$key]) or $val[$key] != $value) { continue; } if (!isset($temp[$val[$key]])) { $temp[$val[$key]] = $key; } else { $temp[$val[$key]] .= " " . $key; } } break; case 'regiontoterritory': $temp = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $value . '\']', 'contains', $value); break; case 'territorytoregion': $_temp2 = self::_getFile('supplementalData', '/supplementalData/territoryContainment/group', 'type'); $_temp = array(); foreach ($_temp2 as $key => $found) { $_temp += self::_getFile('supplementalData', '/supplementalData/territoryContainment/group[@type=\'' . $key . '\']', 'contains', $key); } $temp = array(); foreach ($_temp as $key => $found) { $_temp3 = explode(" ", $found); foreach ($_temp3 as $found3) { if ($found3 !== $value) { continue; } if (!isset($temp[$found3])) { $temp[$found3] = (string) $key; } else { $temp[$found3] .= " " . $key; } } } break; case 'scripttolanguage': $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'scripts', $value); break; case 'languagetoscript': $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type'); $_temp = array(); foreach ($_temp2 as $key => $found) { $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'scripts', $key); } $temp = array(); foreach ($_temp as $key => $found) { $_temp3 = explode(" ", $found); foreach ($_temp3 as $found3) { if ($found3 !== $value) { continue; } if (!isset($temp[$found3])) { $temp[$found3] = (string) $key; } else { $temp[$found3] .= " " . $key; } } } break; case 'territorytolanguage': $temp = self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $value . '\']', 'territories', $value); break; case 'languagetoterritory': $_temp2 = self::_getFile('supplementalData', '/supplementalData/languageData/language', 'type'); $_temp = array(); foreach ($_temp2 as $key => $found) { $_temp += self::_getFile('supplementalData', '/supplementalData/languageData/language[@type=\'' . $key . '\']', 'territories', $key); } $temp = array(); foreach ($_temp as $key => $found) { $_temp3 = explode(" ", $found); foreach ($_temp3 as $found3) { if ($found3 !== $value) { continue; } if (!isset($temp[$found3])) { $temp[$found3] = (string) $key; } else { $temp[$found3] .= " " . $key; } } } break; case 'timezonetowindows': $temp = self::_getFile('windowsZones', '/supplementalData/windowsZones/mapTimezones/mapZone[@other=\'' . $value . '\']', 'type', $value); break; case 'windowstotimezone': $temp = self::_getFile('windowsZones', '/supplementalData/windowsZones/mapTimezones/mapZone[@type=\'' . $value . '\']', 'other', $value); break; case 'territorytotimezone': $temp = self::_getFile('metaZones', '/supplementalData/metaZones/mapTimezones/mapZone[@type=\'' . $value . '\']', 'territory', $value); break; case 'timezonetoterritory': $temp = self::_getFile('metaZones', '/supplementalData/metaZones/mapTimezones/mapZone[@territory=\'' . $value . '\']', 'type', $value); break; case 'citytotimezone': $temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $value . '\']/exemplarCity', '', $value); break; case 'timezonetocity': $_temp = self::_getFile($locale, '/ldml/dates/timeZoneNames/zone', 'type'); $temp = array(); foreach ($_temp as $key => $found) { $temp += self::_getFile($locale, '/ldml/dates/timeZoneNames/zone[@type=\'' . $key . '\']/exemplarCity', '', $key); if (!empty($temp[$key])) { if ($temp[$key] == $value) { $temp[$temp[$key]] = $key; } } unset($temp[$key]); } break; case 'phonetoterritory': $temp = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $value . '\']/telephoneCountryCode', 'code', $value); break; case 'territorytophone': $_temp2 = self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory', 'territory'); $_temp = array(); foreach ($_temp2 as $key => $found) { $_temp += self::_getFile('telephoneCodeData', '/supplementalData/telephoneCodeData/codesByTerritory[@territory=\'' . $key . '\']/telephoneCountryCode', 'code', $key); } $temp = array(); foreach ($_temp as $key => $found) { $_temp3 = explode(" ", $found); foreach ($_temp3 as $found3) { if ($found3 !== $value) { continue; } if (!isset($temp[$found3])) { $temp[$found3] = (string) $key; } else { $temp[$found3] .= " " . $key; } } } break; case 'numerictoterritory': $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $value . '\']', 'numeric', $value); break; case 'territorytonumeric': $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@numeric=\'' . $value . '\']', 'type', $value); break; case 'alpha3toterritory': $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@type=\'' . $value . '\']', 'alpha3', $value); break; case 'territorytoalpha3': $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\'' . $value . '\']', 'type', $value); break; case 'postaltoterritory': $temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $value . '\']', 'territoryId'); break; case 'numberingsystem': $temp = self::_getFile('numberingSystems', '/supplementalData/numberingSystems/numberingSystem[@id=\'' . strtolower($value) . '\']', 'digits', $value); break; case 'chartofallback': $_temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character', 'value'); foreach ($_temp as $key => $keyvalue) { $temp2 = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $key . '\']/substitute', '', $key); if (current($temp2) == $value) { $temp = $key; } } break; $temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $value . '\']/substitute', '', $value); break; case 'fallbacktochar': $temp = self::_getFile('characters', '/supplementalData/characters/character-fallback/character[@value=\'' . $value . '\']/substitute', ''); break; case 'localeupgrade': $temp = self::_getFile('likelySubtags', '/supplementalData/likelySubtags/likelySubtag[@from=\'' . $value . '\']', 'to', $value); break; case 'unit': $temp = self::_getFile($locale, '/ldml/units/unitLength/unit[@type=\'' . $value[0] . '\']/unitPattern[@count=\'' . $value[1] . '\']', ''); break; default: require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php'; throw new IfwPsn_Vendor_Zend_Locale_Exception("Unknown detail ({$path}) for parsing locale data."); break; } if (is_array($temp)) { $temp = current($temp); } if (isset(self::$_cache)) { if (self::$_cacheTags) { self::$_cache->save(serialize($temp), $id, array('IfwPsn_Vendor_Zend_Locale')); } else { self::$_cache->save(serialize($temp), $id); } } return $temp; }
/** * Return the filling percentage of the backend storage * * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return int integer between 0 and 100 */ public function getFillingPercentage() { $mem = wincache_ucache_meminfo(); $memSize = $mem['memory_total']; $memUsed = $memSize - $mem['memory_free']; if ($memSize == 0) { IfwPsn_Vendor_Zend_Cache::throwException('can\'t get WinCache memory size'); } if ($memUsed > $memSize) { return 100; } return (int) (100.0 * ($memUsed / $memSize)); }
/** * Clean some cache records * * Available modes are : * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL (default) => remove all cache entries ($tags is not used) * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_OLD => remove too old cache entries ($tags is not used) * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_TAG => remove cache entries matching all given tags * ($tags can be an array of strings or a single string) * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG => remove cache entries not {matching one of the given tags} * ($tags can be an array of strings or a single string) * IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG => remove cache entries matching any given tags * ($tags can be an array of strings or a single string) * * @param string $mode Clean mode * @param array $tags Array of tags * @throws IfwPsn_Vendor_Zend_Cache_Exception * @return boolean true if no problem */ public function clean($mode = IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL, $tags = array()) { switch ($mode) { case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL: $boolFast = $this->_fastBackend->clean(IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL); $boolSlow = $this->_slowBackend->clean(IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_ALL); return $boolFast && $boolSlow; break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_OLD: return $this->_slowBackend->clean(IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_OLD); case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_TAG: $ids = $this->_slowBackend->getIdsMatchingTags($tags); $res = true; foreach ($ids as $id) { $bool = $this->remove($id); $res = $res && $bool; } return $res; break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_NOT_MATCHING_TAG: $ids = $this->_slowBackend->getIdsNotMatchingTags($tags); $res = true; foreach ($ids as $id) { $bool = $this->remove($id); $res = $res && $bool; } return $res; break; case IfwPsn_Vendor_Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG: $ids = $this->_slowBackend->getIdsMatchingAnyTags($tags); $res = true; foreach ($ids as $id) { $bool = $this->remove($id); $res = $res && $bool; } return $res; break; default: IfwPsn_Vendor_Zend_Cache::throwException('Invalid mode for clean() method'); break; } }