/** * Constructor for the integer validator * * Accepts either a string locale, a Zend_Locale object, or an array or * Zend_Config object containing the keys "locale" and/or "format". * * @param string|Zend_Locale|array|\Zend\Config\Config $options * @throws \Zend\Validator\Exception On empty format */ public function __construct($options = null) { if ($options instanceof \Zend\Config\Config) { $options = $options->toArray(); } if (empty($options)) { if (\Zend\Registry::isRegistered('Zend_Locale')) { $this->setLocale(\Zend\Registry::get('Zend_Locale')); } } elseif (is_array($options)) { // Received if (array_key_exists('locale', $options)) { $this->setLocale($options['locale']); } if (array_key_exists('format', $options)) { $this->setFormat($options['format']); } } elseif ($options instanceof Locale\Locale || is_string($options)) { // Received Locale object or string locale $this->setLocale($options); } $format = $this->getFormat(); if (empty($format)) { throw new Exception\InvalidArgumentException("A postcode-format string has to be given for validation"); } }
/** * Sets validator options * * @param null|string|Locale|array|Traversable $locale OPTIONAL * @return void */ public function __construct($locale = null) { $options = array(); if ($locale instanceof Traversable) { $locale = IteratorToArray::convert($locale); } if (is_array($locale)) { $options = $locale; if (array_key_exists('locale', $locale)) { $locale = $locale['locale']; unset($options['locale']); } else { $locale = null; } } if (empty($locale) && $locale !== false) { if (Registry::isRegistered('Zend_Locale')) { $locale = Registry::get('Zend_Locale'); } } if ($locale !== null) { $this->setLocale($locale); } parent::__construct($options); }
/** * Sets validator options * * @param string|array|Traversable $options OPTIONAL * @return void */ public function __construct($options = array()) { if ($options instanceof Traversable) { $options = IteratorToArray::convert($options); } elseif (!is_array($options)) { $options = func_get_args(); $temp['format'] = array_shift($options); if (!empty($options)) { $temp['locale'] = array_shift($options); } $options = $temp; } if (array_key_exists('format', $options)) { $this->setFormat($options['format']); } if (!array_key_exists('locale', $options)) { if (Registry::isRegistered('Zend_Locale')) { $options['locale'] = Registry::get('Zend_Locale'); } } if (array_key_exists('locale', $options)) { $this->setLocale($options['locale']); } parent::__construct($options); }
/** * Constructor for manually handling * * @param \Zend\Currency\Currency $currency Instance of \Zend\Currency\Currency * @return void */ public function __construct($currency = null) { if ($currency === null) { if (\Zend\Registry::isRegistered('Zend_Currency')) { $currency = \Zend\Registry::get('Zend_Currency'); } } $this->setCurrency($currency); }
public function testOptionsPassedToResourceAreUsedToSetLocaleState() { $resource = new TranslateResource($this->_translationOptions); $resource->setBootstrap($this->bootstrap); $resource->init(); $translate = $resource->getTranslate(); $this->assertTrue(Registry::isRegistered('Zend_Translate')); $this->assertSame(Registry::get('Zend_Translate'), $translate); }
public function testMultiplePlaceholdersUseSameRegistry() { $this->assertTrue(Registry::isRegistered(PlaceholderRegistry::REGISTRY_KEY)); $registry = Registry::get(PlaceholderRegistry::REGISTRY_KEY); $this->assertSame($registry, $this->placeholder->getRegistry()); $placeholder = new Helper\Placeholder(); $this->assertSame($registry, $placeholder->getRegistry()); $this->assertSame($this->placeholder->getRegistry(), $placeholder->getRegistry()); }
/** * Retrieve or create registry instnace * * @return void */ public static function getRegistry() { if (\Zend\Registry::isRegistered(self::REGISTRY_KEY)) { $registry = \Zend\Registry::get(self::REGISTRY_KEY); } else { $registry = new self(); \Zend\Registry::set(self::REGISTRY_KEY, $registry); } return $registry; }
/** * Constructor * * Map constants to doctype strings, and set default doctype */ public function __construct() { if (!Registry::isRegistered($this->_regKey)) { $this->_registry = new ArrayObject(array('doctypes' => array(self::XHTML11 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">', self::XHTML1_RDFA1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">', self::XHTML1_STRICT => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">', self::XHTML1_TRANSITIONAL => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', self::XHTML1_FRAMESET => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">', self::XHTML_BASIC1 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.0//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic10.dtd">', self::XHTML5 => '<!DOCTYPE html>', self::HTML4_STRICT => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">', self::HTML4_LOOSE => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">', self::HTML4_FRAMESET => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">', self::HTML5 => '<!DOCTYPE html>'))); Registry::set($this->_regKey, $this->_registry); $this->setDoctype($this->_defaultDoctype); } else { $this->_registry = Registry::get($this->_regKey); } }
public function testOptionsPassedToResourceAreUsedToSetLocaleState1() { $this->markTestSkipped('Skipped until Zend\\Locale and the Resource can be further examined. Logic in the resource and in Locale do not match up.'); $options = array('default' => 'kok_IN'); $resource = new LocaleResource($options); $resource->setBootstrap($this->bootstrap); $resource->init(); $locale = $resource->getLocale(); var_dump($locale->__toString()); // This test will fail if your configured locale is kok_IN $this->assertFalse('kok_IN' == $locale->__toString()); $this->assertSame(Registry::get('Zend_Locale'), $locale); }
function __construct() { $this->open_connection(); $this->magic_quotes_active = get_magic_quotes_gpc(); $this->real_escape_string_exists = function_exists("mysql_real_escape_string"); // $this->cache = new Memcache(); // $this->cache->connect(CACHE_SERVER, CACHE_PORT) or die ("Could not connect"); $this->zend_cache = Zend_Cache::factory('Core', 'File', array('lifetime' => 3600 * 24, 'automatic_serialization' => true), array('cache_dir' => SITE_ROOT . '/cache_files')); Zend_Registry::set('cached', $this->zend_cache); //<---set a registry refference $this->zend_cache = Zend_Registry::get('cached'); //<---gets the a registry refference }
/** * Constructor * * @param string $value * @param array $columns * @param array|string $cache * @param string $criteria */ public function __construct($value, $columns, $cache, $criteria = self::CRITERIA_BEGINS) { parent::__construct($columns, $value); if (empty($cache)) { $this->_cache = false; } elseif (is_array($cache)) { $this->_cache = $cache; } else { $this->_cache = \Zend\Registry::get($cache); } $this->_criteria = $criteria; $this->_setValue(); }
/** * Constructor for the integer validator * * Accepts either a string locale, a Zend_Locale object, or an array or * Zend_Config object containing the keys "locale" and/or "format". * * @param string|Zend_Locale|array|\Zend\Config\Config $options * @throws \Zend\Validator\Exception On empty format */ public function __construct($options = null) { if (empty($options)) { if (\Zend\Registry::isRegistered('Zend_Locale')) { $this->setLocale(\Zend\Registry::get('Zend_Locale')); } } elseif ($options instanceof Locale\Locale || is_string($options)) { // Received Locale object or string locale $this->setLocale($options); } parent::__construct($options); $format = $this->getFormat(); if (empty($format)) { throw new Exception\InvalidArgumentException("A postcode-format string has to be given for validation"); } }
public function testShouldProxyToMenuHelperByDeafult() { // setup $oldReg = null; if (\Zend\Registry::isRegistered(self::REGISTRY_KEY)) { $oldReg = \Zend\Registry::get(self::REGISTRY_KEY); } \Zend\Registry::set(self::REGISTRY_KEY, $this->_nav1); $this->_helper->setContainer(null); // result $expected = $this->_getExpected('menu/default1.html'); $actual = $this->_helper->render(); // teardown \Zend\Registry::set(self::REGISTRY_KEY, $oldReg); $this->assertEquals($expected, $actual); }
/** * Constructor for the float validator * * @param string|Zend_Config|\Zend\Locale\Locale $locale */ public function __construct($locale = null) { if ($locale instanceof \Zend\Config\Config) { $locale = $locale->toArray(); } if (is_array($locale)) { if (array_key_exists('locale', $locale)) { $locale = $locale['locale']; } else { $locale = null; } } if (empty($locale)) { if (\Zend\Registry::isRegistered('Zend_Locale')) { $locale = \Zend\Registry::get('Zend_Locale'); } } $this->setLocale($locale); }
/** * Constructor for the integer validator * * @param array|Traversable|\Zend\Locale\Locale|string $options */ public function __construct($options = null) { if ($options instanceof Traversable) { $options = ArrayUtils::iteratorToArray($options); } if (is_array($options)) { if (array_key_exists('locale', $options)) { $options = $options['locale']; } else { $options = null; } } if (empty($options)) { if (\Zend\Registry::isRegistered('Zend_Locale')) { $options = \Zend\Registry::get('Zend_Locale'); } } if ($options !== null) { $this->setLocale($options); } parent::__construct(); }
/** * Finds the proper locale based on the input * Checks if it exists, degrades it when necessary * Detects registry locale and when all fails tries to detect a automatic locale * Returns the found locale as string * * @param string $locale * @throws \Zend\Locale\Exception\InvalidArgumentException When the given locale is no locale or the autodetection fails * @return string */ public static function findLocale($locale = null) { if ($locale === null) { if (Registry::isRegistered('Zend_Locale')) { $locale = Registry::get('Zend_Locale'); } } if ($locale === null) { $locale = new Locale(); } if (!Locale::isLocale($locale, true)) { if (!Locale::isLocale($locale, false)) { $locale = Locale::getLocaleToTerritory($locale); if (empty($locale)) { throw new Exception\InvalidArgumentException("The locale '{$locale}' is no known locale"); } } else { $locale = new self($locale); } } $locale = self::_prepareLocale($locale); return $locale; }
/** * Retrieve translate object * * @return \Zend\Translator\Translator * @throws \Zend\Application\ResourceException if registry key was used * already but is no instance of Zend_Translator */ public function getTranslate() { if (null === $this->_translate) { $options = $this->getOptions(); if (!isset($options['data'])) { throw new Exception\InitializationException('No translation source data provided.'); } if (empty($options['adapter'])) { $options['adapter'] = Translator::AN_ARRAY; } if (!empty($options['data'])) { $options['content'] = $options['data']; unset($options['data']); } if (isset($options['options'])) { foreach ($options['options'] as $key => $value) { $options[$key] = $value; } } if (!empty($options['cache']) && is_string($options['cache'])) { $bootstrap = $this->getBootstrap(); if ($bootstrap instanceof \Zend\Application\ResourceBootstrapper && $bootstrap->getBroker()->hasPlugin('CacheManager')) { $cacheManager = $bootstrap->bootstrap('CacheManager')->getResource('CacheManager'); if (null !== $cacheManager && $cacheManager->hasCache($options['cache'])) { $options['cache'] = $cacheManager->getCache($options['cache']); } } } $key = isset($options['registry_key']) && !is_numeric($options['registry_key']) ? $options['registry_key'] : self::DEFAULT_REGISTRY_KEY; unset($options['registry_key']); if (Registry::isRegistered($key)) { $translate = Registry::get($key); if (!$translate instanceof Translator) { throw new Exception\InitializationException($key . ' already registered in registry but is ' . 'no instance of Zend_Translator'); } $translate->addTranslation($options); $this->_translate = $translate; } else { $this->_translate = new Translator($options); Registry::set($key, $this->_translate); } } return $this->_translate; }
/** * Return translation object * * @return Zend\Translate\Adapter\Adapter|null */ public function getTranslator() { if ($this->translatorIsDisabled()) { return null; } if ($this->_translator === null) { if (\Zend\Registry::isRegistered('Zend_Translate')) { $translator = \Zend\Registry::get('Zend_Translate'); if ($translator instanceof TranslationAdapter) { return $translator; } elseif ($translator instanceof Translator) { return $translator->getAdapter(); } } } return $this->_translator; }
public function testBootstrapShouldInvokeCallbackSpecifiedInPublicBootstrapProperty() { $this->testCase->bootstrap = array($this, 'bootstrapCallback'); $this->testCase->bootstrap(); $controller = $this->testCase->getFrontController(); $broker = $controller->getHelperBroker(); $this->assertSame(Registry::get('router'), $controller->getRouter()); $this->assertSame(Registry::get('dispatcher'), $controller->getDispatcher()); $this->assertSame(Registry::get('plugin'), $controller->getPlugin('Zend\\Controller\\Plugin\\ErrorHandler')); $this->assertSame(Registry::get('viewRenderer'), $broker->load('ViewRenderer')); }
/** * Get the locale * * @return mixed */ public function getLocale() { if ($this->_locale !== null) { return $this->_locale; } else if (($locale = self::getDefaultLocale()) !== null) { return $locale; } else { try { $locale = \Zend\Registry::get('Zend_Locale'); } catch (\Zend\Exception $e) { $locale = null; } if ($locale !== null) { return $locale; } } return null; }
public function testStringificationReturnsDoctypeString() { $doctype = $this->helper->__invoke('XHTML1_STRICT'); $string = $doctype->__toString(); $registry = \Zend\Registry::get('Zend_View_Helper_Doctype'); $this->assertEquals($registry['doctypes']['XHTML1_STRICT'], $string); }
public function testTranslationFromTranslatorInRegistry() { $oldReg = \Zend\Registry::isRegistered('Zend_Translator') ? \Zend\Registry::get('Zend_Translator') : null; $translator = $this->_getTranslator(); \Zend\Registry::set('Zend_Translator', $translator); $expected = $this->_getExpected('bc/translated.html'); $actual = $this->_helper->render(); \Zend\Registry::set('Zend_Translator', $oldReg); $this->assertEquals($expected, $actual); }
/** * Retrieve translation object * * @return TranslationAdapter|null */ public function getTranslator() { if ($this->translator === null) { if (Registry::isRegistered('Zend_Translator')) { $this->setTranslator(Registry::get('Zend_Translator')); } } return $this->translator; }
public function testGetRegistryRegistersWithGlobalRegistry() { $this->assertFalse(\Zend\Registry::isRegistered(Registry::REGISTRY_KEY)); $registry = Registry::getRegistry(); $this->assertTrue(\Zend\Registry::isRegistered(Registry::REGISTRY_KEY)); $registered = \Zend\Registry::get(Registry::REGISTRY_KEY); $this->assertSame($registry, $registered); }
/** * Get global default translator object * * @return null|Translator\Translator|Translator\Adapter */ public static function getDefaultTranslator() { if (null === self::$_translatorDefault) { if (Registry::isRegistered('Zend_Translator')) { $translator = Registry::get('Zend_Translator'); if ($translator instanceof Translator\Adapter\AbstractAdapter) { return $translator; } elseif ($translator instanceof Translator\Translator) { return $translator->getAdapter(); } } } return self::$_translatorDefault; }
/** * Returns translator used in helper * * Implements {@link Zend_View_Helper_Navigation_Helper::getTranslator()}. * * @return \Zend\Translator\Adapter\Adapter|null translator or null */ public function getTranslator() { if (null === $this->_translator) { if (\Zend\Registry::isRegistered('Zend_Translate')) { $this->setTranslator(\Zend\Registry::get('Zend_Translate')); } } return $this->_translator; }
/** * Sets a new locale for the value representation * * @param string|Zend\Locale\Locale $locale (Optional) New locale to set * @param boolean $check False, check but don't set; True, set the new locale * @return Zend\Measure\AbstractMeasure */ public function setLocale($locale = null, $check = false) { if (empty($locale)) { if (Registry::isRegistered('Zend_Locale') === true) { $locale = Registry::get('Zend_Locale'); } } if ($locale === null) { $locale = new Locale\Locale(); } if (!Locale\Locale::isLocale($locale, true)) { if (!Locale\Locale::isLocale($locale, false)) { throw new Exception("Language (" . (string) $locale . ") is unknown"); } $locale = new Locale\Locale($locale); } if (!$check) { $this->_locale = (string) $locale; } return $this; }
public function testAutoloadContainerFromRegistry() { $oldReg = null; if (\Zend\Registry::isRegistered(self::REGISTRY_KEY)) { $oldReg = \Zend\Registry::get(self::REGISTRY_KEY); } \Zend\Registry::set(self::REGISTRY_KEY, $this->_nav1); $this->_helper->setContainer(null); $expected = $this->_getExpected('sitemap/default1.xml'); $actual = $this->_helper->render(); \Zend\Registry::set(self::REGISTRY_KEY, $oldReg); $this->assertEquals($expected, $expected); }
public function testDefaultRegistryArrayAsPropsZF4654() { $registry = Registry::getInstance(); $registry->bar = "baz"; $this->assertEquals('baz', Registry::get('bar')); }
/** * @param mixed $metadataCache Either a Cache object, or a string naming a Registry key * @return \Zend\Cache\Frontend\Core * @throws \Zend\DB\Table\Exception */ protected static function _setupMetadataCache($metadataCache) { if ($metadataCache === null) { return null; } if (is_string($metadataCache)) { $metadataCache = \Zend\Registry::get($metadataCache); } if (!$metadataCache instanceof \Zend\Cache\Frontend\Core) { throw new Exception('Argument must be of type Zend_Cache_Core, or a Registry key where a Zend_Cache_Core object is stored'); } return $metadataCache; }