getFileCache( 'country', $locale, array(&$this, '_countryCacheMiss') ); // Check to see if the data is outdated $cacheTime = $caches[$locale]->getCacheTime(); if ($cacheTime !== null && $cacheTime < filemtime($this->getFilename())) { $caches[$locale]->flush(); } } return $caches[$locale]; } function _countryCacheMiss(&$cache, $id) { static $countries; if (!isset($countries)) { $countries = array(); } if (!isset($countries[$id])) { // Reload country registry file $xmlDao = &new XMLDAO(); $data = $xmlDao->parseStruct($this->getFilename(), array('countries', 'country')); if (isset($data['countries'])) { foreach ($data['country'] as $countryData) { $countries[$id][$countryData['attributes']['code']] = $countryData['attributes']['name']; } } asort($countries[$id]); $cache->setEntireCache($countries[$id]); } return null; } /** * Return a list of all countries. * @param $locale string Name of locale (optional) * @return array */ function &getCountries($locale = null) { $cache =& $this->_getCountryCache($locale); return $cache->getContents(); } /** * Return a translated country name, given a code. * @param $locale string Name of locale (optional) * @return array */ function getCountry($code, $locale = null) { $cache =& $this->_getCountryCache($locale); return $cache->get($code); } } ?>