/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. * * @return void */ public function setUp() { $this->clearRegistry(); $this->_cache = Cache\Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => sys_get_temp_dir())); Currency\Currency::setCache($this->_cache); $this->helper = new Helper\Currency('de_AT'); }
protected function setUp() { if (!extension_loaded('pdo_sqlite')) { $this->markTestSkipped('Pdo_Sqlite extension is not loaded'); } $this->_adapter = new \Zend\Db\Adapter\Pdo\Sqlite(array( 'dbname' => __DIR__ . '/_files/test.sqlite' )); $this->_query = $this->_adapter->select()->from('test'); $this->_testCollection = range(1, 101); $this->_paginator = Paginator\Paginator::factory($this->_testCollection); $this->_config = new Config\Xml(__DIR__ . '/_files/config.xml'); // get a fresh new copy of ViewRenderer in each tests $this->front = FrontController::getInstance(); $this->front->resetInstance(); $this->broker = $this->front->getHelperBroker(); $fO = array('lifetime' => 3600, 'automatic_serialization' => true); $bO = array('cache_dir'=> $this->_getTmpDir()); $this->_cache = \Zend\Cache\Cache::factory('Core', 'File', $fO, $bO); Paginator\Paginator::setCache($this->_cache); $this->_restorePaginatorDefaults(); }
public function setUp($notag = false) { $this->mkdir(); $this->_cache_dir = $this->mkdir(); @mkdir($this->_cache_dir.'/tags'); $this->_innerCache = Cache\Cache::factory('Core','File', array('automatic_serialization'=>true), array('cache_dir'=>$this->_cache_dir.'/tags') ); $this->_instance = new Cache\Backend\StaticBackend(array( 'public_dir' => $this->_cache_dir, 'tag_cache' => $this->_innerCache )); $logger = new \Zend\Log\Logger(new \Zend\Log\Writer\Null()); $this->_instance->setDirectives(array('logger' => $logger)); $this->_requestUriOld = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null; $_SERVER['REQUEST_URI'] = '/foo'; $this->_instance->setDirectives(array('logging' => true)); $this->_instance->save('bar : data to cache', bin2hex('/bar'), array('tag3', 'tag4')); $this->_instance->save('bar2 : data to cache', bin2hex('/bar2'), array('tag3', 'tag1')); $this->_instance->save('bar3 : data to cache', bin2hex('/bar3'), array('tag2', 'tag3')); }
public function setUp() { $this->originalTimezone = date_default_timezone_get(); date_default_timezone_set('Europe/Paris'); $this->_cache = Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => dirname(__FILE__) . '/../_files/')); DateObjectTestHelper::setOptions(array('cache' => $this->_cache)); }
public function setUp() { $this->_cache = Cache::factory('Core', 'File', array('lifetime' => 1, 'automatic_serialization' => true), array('cache_dir' => __DIR__ . '/../../_files/')); Cldr::setCache($this->_cache); }
/** * Enter description here... * * @return \Zend\Service\SlideShare */ protected function _getSSObject() { $ss = new SlideShareService(TESTS_ZEND_SERVICE_SLIDESHARE_APIKEY, TESTS_ZEND_SERVICE_SLIDESHARE_SHAREDSECRET, TESTS_ZEND_SERVICE_SLIDESHARE_USERNAME, TESTS_ZEND_SERVICE_SLIDESHARE_PASSWORD, TESTS_ZEND_SERVICE_SLIDESHARE_SLIDESHOWID); $cache = Cache::factory('Core', 'File', array('lifetime' => 0, 'automatic_serialization' => true), array('cache_dir' => __DIR__ . "/_files")); $ss->setCacheObject($cache); return $ss; }
/** * @group ZF-10033 */ public function testSetDefaultMetadataCache() { $cache = \Zend\Cache\Cache::factory('Core', 'BlackHole', array('lifetime' => 120, 'automatic_serialization' => true)); $config = array('adapter' => 'Pdo\\Sqlite', 'params' => array('dbname' => ':memory:'), 'defaultMetadataCache' => $cache); $resource = new DbResource($config); $resource->init(); $this->assertInstanceOf('Zend\\Cache\\Frontend', \Zend\Db\Table\AbstractTable::getDefaultMetadataCache()); }
public function setUp() { $this->_cache_dir = $this->mkdir(); $this->_cache = Cache\Cache::factory( 'Core', 'File', array('automatic_serialization'=>true), array('cache_dir'=>$this->_cache_dir) ); }
public function setUp() { $this->_locale = setlocale(LC_ALL, 0); setlocale(LC_ALL, 'de'); $this->_cache = Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => __DIR__ . '/../_files/')); LocaleTestHelper::resetObject(); LocaleTestHelper::setCache($this->_cache); putenv("HTTP_ACCEPT_LANGUAGE=,de,en-UK-US;q=0.5,fr_FR;q=0.2"); }
public function setUp() { $this->_locale = setlocale(LC_ALL, 0); setlocale(LC_ALL, 'de'); $this->_cache = Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => __DIR__ . '/../_files/')); LocaleTestHelper::resetObject(); LocaleTestHelper::setCache($this->_cache); // compatibilityMode is true until 1.8 therefor we have to change it LocaleTestHelper::$compatibilityMode = false; putenv("HTTP_ACCEPT_LANGUAGE=,de,en-UK-US;q=0.5,fr_FR;q=0.2"); }
public function setUp() { $cache = Cache\Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => dirname(__FILE__) . '/_files/')); Currency\Currency::setCache($cache); }
public function testBackendBadParam() { Cache\Cache::factory('Output', 'badBackend', array(), array('badParam' => true)); }
/** * Gets the Zend\Cache object which will be used to cache API queries. If no cache object * was previously set the the default will be used (Filesystem caching in /tmp with a life * time of 43200 seconds) * * @return Zend\Cache\Frontend\Core The object used in caching */ public function getCacheObject() { if(!($this->_cacheobject instanceof Frontend\Core)) { $cache = \Zend\Cache\Cache::factory('Core', 'File', array('lifetime' => 43200, 'automatic_serialization' => true), array('cache_dir' => '/tmp')); $this->setCacheObject($cache); } return $this->_cacheobject; }
/** * ZF-9877 */ public function testSetCacheThroughOptions() { $cache = Cache\Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => __DIR__ . '/../_files/')); $translate = new Translator\Translator(array('adapter' => Translator\Translator::AN_ARRAY, 'content' => array('msg1' => 'Message 1 (en)'), 'locale' => 'en', 'cache' => $cache)); $return = Translator\Translator::getCache(); $this->assertTrue($return instanceof Cache\Frontend); $this->assertTrue(Translator\Translator::hasCache()); }
/** * Returns a clean Zend_Cache_Core with File backend * * @return Zend_Cache_Core */ protected function _getCacheNowrite() { /** * @see Zend_Cache */ $folder = __DIR__ . DIRECTORY_SEPARATOR . '../_files' . DIRECTORY_SEPARATOR . 'nofiles'; if (!file_exists($folder)) { mkdir($folder, 0777); } $frontendOptions = array('automatic_serialization' => true); $backendOptions = array('cache_dir' => $folder, 'file_name_prefix' => 'Zend_Db_Table_TestCommon'); $cacheFrontend = Cache\Cache::factory('Core', 'File', $frontendOptions, $backendOptions); $cacheFrontend->clean(Cache\Cache::CLEANING_MODE_ALL); rmdir($folder); return $cacheFrontend; }
/** * Fetch the named cache object, or instantiate and return a cache object * using a named configuration template * * @param string $name * @return \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 Core)) { $this->_optionTemplates[$name]['backend']['options']['tag_cache'] = $this->getCache(self::PAGETAGCACHE); } $this->_caches[$name] = 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]; } }
/** * @group ZF-10049 */ public function testSetDefaultMetadataCache() { $cache = Cache::factory('Core', 'BlackHole', array('lifetime' => 120, 'automatic_serialization' => true)); $options = $this->_dbOptions; $options['defaultMetadataCache'] = $cache; $resource = new MultidbResource($options); $resource->init(); $this->assertType('Zend\\Cache\\Frontend\\Core', DBTable::getDefaultMetadataCache()); }
public function testSetOptions() { $options = Date::setOptions(); $this->assertTrue(is_array($options)); $this->assertEquals('iso', $options['format_type']); Date::setOptions(array('format_type' => 'php')); $options = Date::setOptions(); $this->assertEquals('php', $options['format_type']); try { Date::setOptions(array('format_type' => 'non')); $this->fail(); } catch (\Zend\Date\Exception $e) { // success } try { Date::setOptions(array('unknown' => 'non')); $this->fail(); } catch (\Zend\Date\Exception $e) { // success } try { Date::setOptions(array('fix_dst' => 2)); $this->fail(); } catch (\Zend\Date\Exception $e) { // success } try { Date::setOptions(array('fix_dst' => 2)); $this->fail(); } catch (\Zend\Date\Exception $e) { // success } $cache = Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => __DIR__ . '/../_files/')); Date::setOptions(array('cache' => $cache)); }
public function testBadBackend() { try { Cache\Cache::factory('Output', 'badBackend'); } catch (Cache\Exception $e) { return; } $this->fail('Zend_Exception was expected but not thrown'); }
/** * Read the LDML file, get a single path defined value * * @param string $locale * @param string $path * @param string $value * @throws \Zend\Locale\Exception\InvalidArgumentException * @return string */ public static function getContent($locale, $path, $value = false) { $locale = self::_checkLocale($locale); if (!isset(self::$_cache) && !self::$_cacheDisabled) { self::$_cache = Cache::factory('Core', 'File', array('automatic_serialization' => true), array()); } $val = $value; if (is_array($value)) { $val = implode('_', $value); } $val = urlencode($val); $id = strtr('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': $temp = self::_getFile($locale, '/ldml/dates/calendars/default', 'choice', 'default'); break; case 'monthcontext': if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/default', 'choice', 'context'); break; case 'defaultmonth': if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/months/monthContext[@type=\'format\']/default', 'choice', 'default'); 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': if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/default', 'choice', 'context'); break; case 'defaultday': if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/days/dayContext[@type=\'format\']/default', 'choice', 'default'); 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 = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/am', '', 'am'); break; case 'pm': if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/pm', '', 'pm'); 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': if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/dateFormats/default', 'choice', 'default'); 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': if (empty($value)) { $value = "gregorian"; } $temp = self::_getFile($locale, '/ldml/dates/calendars/calendar[@type=\'' . $value . '\']/timeFormats/default', 'choice', 'default'); 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/calendars/calendar[@type=\'' . $value[0] . '\']/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/calendars/calendar[@type=\'' . $value[0] . '\']/fields/field/relative[@type=\'' . $value[1] . '\']', '', $value[1]); 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('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@other=\'' . $value . '\']', 'type', $value); break; case 'windowstotimezone': $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/mapTimezones[@type=\'windows\']/mapZone[@type=\'' . $value . '\']', 'other', $value); break; case 'territorytotimezone': $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@type=\'' . $value . '\']', 'territory', $value); break; case 'timezonetoterritory': $temp = self::_getFile('supplementalData', '/supplementalData/timezoneData/zoneFormatting/zoneItem[@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/unit[@type=\'' . $value[0] . '\']/unitPattern[@count=\'' . $value[1] . '\']', ''); break; default: throw new Exception\InvalidArgumentException("Unknown detail ({$path}) for parsing locale data."); break; } if (is_array($temp)) { $temp = current($temp); } if (isset(self::$_cache)) { self::$_cache->save(serialize($temp), $id); } return $temp; }
<?php require_once dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . 'Bootstrap.php'; use Zend\Cache\Cache; use Zend\Service\LiveDocx\Helper; use Zend\Service\LiveDocx\MailMerge; Helper::printLine(PHP_EOL . 'Template, Document and Image Formats' . PHP_EOL . PHP_EOL . 'The following formats are supported by LiveDocx:' . PHP_EOL . PHP_EOL . '(Note these method calls are cached for maximum performance. The supported formats change very infrequently, hence, they are good candidates to be cached.)' . PHP_EOL . PHP_EOL); $cacheId = md5(__FILE__); $cacheFrontendOptions = array('lifetime' => 2592000, 'automatic_serialization' => true); $cacheBackendOptions = array('cache_dir' => __DIR__ . '/cache'); if (!is_dir($cacheBackendOptions['cache_dir'])) { mkdir($cacheBackendOptions['cache_dir']); } $cache = Cache::factory('Core', 'File', $cacheFrontendOptions, $cacheBackendOptions); if (!($formats = $cache->load($cacheId))) { // Cache miss. Connect to backend service (expensive). $mailMerge = new MailMerge(); $mailMerge->setUsername(DEMOS_ZEND_SERVICE_LIVEDOCX_USERNAME)->setPassword(DEMOS_ZEND_SERVICE_LIVEDOCX_PASSWORD); $formats = new \StdClass(); $formats->template = $mailMerge->getTemplateFormats(); $formats->document = $mailMerge->getDocumentFormats(); $formats->image = $mailMerge->getImageFormats(); $cache->save($formats, $cacheId); unset($mailMerge); } else { // Cache hit. Continue. } unset($cache); printf("Supported TEMPLATE file formats (input) : %s%s", Helper::arrayDecorator($formats->template), PHP_EOL); printf("Supported DOCUMENT file formats (output) : %s%s", Helper::arrayDecorator($formats->document), PHP_EOL); printf("Supported IMAGE file formats (output) : %s%s", Helper::arrayDecorator($formats->image), PHP_EOL);
/** * Sets the default cache * * @return void */ protected static function setDefaultCache() { if (!is_dir(self::getPath() . '/cache')) { mkdir(self::getPath() . '/cache', 0, true); } if (!is_dir(self::getPath() . '/cache')) { // caching impossible... throw notice return false; } self::setCache(Cache::factory('Core', 'File', array('automatic_serialization' => true, 'automatic_cleaning_factor' => 0, 'lifetime' => null), array('cache_dir' => self::getPath() . '/cache', 'read_control_type' => 'strlen'))); self::_getTagSupportForCache(); }
public function testLoadingFilesIntoCacheAfterwards() { $cache = Cache\Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => dirname(__FILE__) . '/_files/')); $this->assertFalse(Adapter\ArrayAdapter::hasCache()); Adapter\ArrayAdapter::setCache($cache); $this->assertTrue(Adapter\ArrayAdapter::hasCache()); $adapter = new Adapter\ArrayAdapter(dirname(__FILE__) . '/_files/translation_en.php', 'en'); $cache = Adapter\ArrayAdapter::getCache(); $this->assertTrue($cache instanceof Frontend\Core); $adapter->addTranslation(dirname(__FILE__) . '/_files/translation_en.php', 'ru', array('reload' => true)); $test = $adapter->getMessages('all'); $this->assertEquals(6, count($test['ru'])); }
/** * Tests if cached options are read from the cache for a new instance */ public function testGetOptionsFromCache() { $cache = Cache\Cache::factory('Core', 'File', array('lifetime' => 120, 'automatic_serialization' => true), array('cache_dir' => dirname(__FILE__) . '/_files/')); Translator\Translator::setCache($cache); $lang = new Translator\Translator(Translator\Translator::AN_CSV, dirname(__FILE__) . '/Adapter/_files', 'en', array('delimiter' => ',')); $lang->setOptions(array('logMessage' => 'test')); $this->assertEquals('test', $lang->getOptions('logMessage')); unset($lang); $lang2 = new Translator\Translator(Translator\Translator::AN_CSV, dirname(__FILE__) . '/Adapter/_files', 'en', array('delimiter' => ',')); $this->assertEquals('test', $lang2->getOptions('logMessage')); }