/** * Constructor for the integer validator * * Accepts either a string locale, a IfwPsn_Vendor_Zend_Locale object, or an array or * IfwPsn_Vendor_Zend_Config object containing the keys "locale" and/or "format". * * @param string|IfwPsn_Vendor_Zend_Locale|array|IfwPsn_Vendor_Zend_Config $options * @throws IfwPsn_Vendor_Zend_Validate_Exception On empty format */ public function __construct($options = null) { if ($options instanceof IfwPsn_Vendor_Zend_Config) { $options = $options->toArray(); } if (empty($options)) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Registry.php'; if (IfwPsn_Vendor_Zend_Registry::isRegistered('IfwPsn_Vendor_Zend_Locale')) { $this->setLocale(IfwPsn_Vendor_Zend_Registry::get('IfwPsn_Vendor_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 IfwPsn_Vendor_Zend_Locale || is_string($options)) { // Received Locale object or string locale $this->setLocale($options); } $format = $this->getFormat(); if (empty($format)) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Validate/Exception.php'; throw new IfwPsn_Vendor_Zend_Validate_Exception("A postcode-format string has to be given for validation"); } }
/** * Returns TRUE if the $index is a named value in the registry, * or FALSE if $index was not found in the registry. * * @param string $index * @return boolean */ public static function isRegistered($index) { if (self::$_registry === null) { return false; } return self::$_registry->offsetExists($index); }
/** * Sets validator options * * @param string|IfwPsn_Vendor_Zend_Config $options OPTIONAL * @return void */ public function __construct($options = array()) { if ($options instanceof IfwPsn_Vendor_Zend_Config) { $options = $options->toArray(); } else { if (!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)) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Registry.php'; if (IfwPsn_Vendor_Zend_Registry::isRegistered('IfwPsn_Vendor_Zend_Locale')) { $options['locale'] = IfwPsn_Vendor_Zend_Registry::get('IfwPsn_Vendor_Zend_Locale'); } } if (array_key_exists('locale', $options)) { $this->setLocale($options['locale']); } }
/** * Retrieve or create registry instnace * * @return void */ public static function getRegistry() { if (IfwPsn_Vendor_Zend_Registry::isRegistered(self::REGISTRY_KEY)) { $registry = IfwPsn_Vendor_Zend_Registry::get(self::REGISTRY_KEY); } else { $registry = new self(); IfwPsn_Vendor_Zend_Registry::set(self::REGISTRY_KEY, $registry); } return $registry; }
/** * Constructor for manually handling * * @param IfwPsn_Vendor_Zend_Currency $currency Instance of IfwPsn_Vendor_Zend_Currency * @return void */ public function __construct($currency = null) { if ($currency === null) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Registry.php'; if (IfwPsn_Vendor_Zend_Registry::isRegistered('IfwPsn_Vendor_Zend_Currency')) { $currency = IfwPsn_Vendor_Zend_Registry::get('IfwPsn_Vendor_Zend_Currency'); } } $this->setCurrency($currency); }
/** * Constructor * * Map constants to doctype strings, and set default doctype * * @return void */ public function __construct() { if (!IfwPsn_Vendor_Zend_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_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::XHTML1_RDFA => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">', self::XHTML1_RDFA11 => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.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>'))); IfwPsn_Vendor_Zend_Registry::set($this->_regKey, $this->_registry); $this->setDoctype($this->_defaultDoctype); } else { $this->_registry = IfwPsn_Vendor_Zend_Registry::get($this->_regKey); } }
/** * Constructor * * @param IfwPsn_Vendor_Zend_Registry $registry * @param string $key * @return void */ public function __construct(IfwPsn_Vendor_Zend_Registry $registry = null, $key = null) { if (null === $registry) { $registry = IfwPsn_Vendor_Zend_Registry::getInstance(); } $this->setRegistry($registry); if (null !== $key) { $this->setRegistryKey($key); } else { $key = $this->getRegistryKey(); } $registry[$key] = array(); }
/** * Retrieve locale object * * @return IfwPsn_Vendor_Zend_Locale */ public function getLocale() { if (null === $this->_locale) { $options = $this->getOptions(); if (!isset($options['default'])) { $this->_locale = new IfwPsn_Vendor_Zend_Locale(); } elseif (!isset($options['force']) || (bool) $options['force'] == false) { // Don't force any locale, just go for auto detection IfwPsn_Vendor_Zend_Locale::setDefault($options['default']); $this->_locale = new IfwPsn_Vendor_Zend_Locale(); } else { $this->_locale = new IfwPsn_Vendor_Zend_Locale($options['default']); } $key = isset($options['registry_key']) && !is_numeric($options['registry_key']) ? $options['registry_key'] : self::DEFAULT_REGISTRY_KEY; IfwPsn_Vendor_Zend_Registry::set($key, $this->_locale); } return $this->_locale; }
/** * Constructor for the float validator * * @param string|IfwPsn_Vendor_Zend_Config|IfwPsn_Vendor_Zend_Locale $locale */ public function __construct($locale = null) { if ($locale instanceof IfwPsn_Vendor_Zend_Config) { $locale = $locale->toArray(); } if (is_array($locale)) { if (array_key_exists('locale', $locale)) { $locale = $locale['locale']; } else { $locale = null; } } if (empty($locale)) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Registry.php'; if (IfwPsn_Vendor_Zend_Registry::isRegistered('IfwPsn_Vendor_Zend_Locale')) { $locale = IfwPsn_Vendor_Zend_Registry::get('IfwPsn_Vendor_Zend_Locale'); } } $this->setLocale($locale); }
/** * Retrieve translation object * * @return IfwPsn_Vendor_Zend_Translate_Adapter|null */ public function getTranslator() { if ($this->_translator === null) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Registry.php'; if (IfwPsn_Vendor_Zend_Registry::isRegistered('IfwPsn_Vendor_Zend_Translate')) { $this->setTranslator(IfwPsn_Vendor_Zend_Registry::get('IfwPsn_Vendor_Zend_Translate')); } } return $this->_translator; }
/** * 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 = IfwPsn_Vendor_Zend_Registry::get('IfwPsn_Vendor_Zend_Locale'); } catch (IfwPsn_Vendor_Zend_Exception $e) { $locale = null; } if ($locale !== null) { return $locale; } } } return null; }
/** * 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 IfwPsn_Vendor_Zend_Locale_Exception When the given locale is no locale or the autodetection fails * @return string */ public static function findLocale($locale = null) { if ($locale === null) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Registry.php'; if (IfwPsn_Vendor_Zend_Registry::isRegistered('IfwPsn_Vendor_Zend_Locale')) { $locale = IfwPsn_Vendor_Zend_Registry::get('IfwPsn_Vendor_Zend_Locale'); } } if ($locale === null) { $locale = new IfwPsn_Vendor_Zend_Locale(); } if (!IfwPsn_Vendor_Zend_Locale::isLocale($locale, true, false)) { if (!IfwPsn_Vendor_Zend_Locale::isLocale($locale, false, false)) { $locale = IfwPsn_Vendor_Zend_Locale::getLocaleToTerritory($locale); if (empty($locale)) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Locale/Exception.php'; throw new IfwPsn_Vendor_Zend_Locale_Exception("The locale '{$locale}' is no known locale"); } } else { $locale = new IfwPsn_Vendor_Zend_Locale($locale); } } $locale = self::_prepareLocale($locale); return $locale; }
/** * Get global default translator object * * @return null|IfwPsn_Vendor_Zend_Translate */ public static function getDefaultTranslator() { if (null === self::$_translatorDefault) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Registry.php'; if (IfwPsn_Vendor_Zend_Registry::isRegistered('IfwPsn_Vendor_Zend_Translate')) { $translator = IfwPsn_Vendor_Zend_Registry::get('IfwPsn_Vendor_Zend_Translate'); if ($translator instanceof IfwPsn_Vendor_Zend_Translate_Adapter) { return $translator; } elseif ($translator instanceof IfwPsn_Vendor_Zend_Translate) { return $translator->getAdapter(); } } } return self::$_translatorDefault; }
/** * Stores navigation container in the registry * * @return void */ protected function _storeRegistry() { $options = $this->getOptions(); if (isset($options['storage']['registry']['key']) && !is_numeric($options['storage']['registry']['key'])) { $key = $options['storage']['registry']['key']; } else { $key = self::DEFAULT_REGISTRY_KEY; } IfwPsn_Vendor_Zend_Registry::set($key, $this->getContainer()); }
/** * Retrieve translate object * * @return IfwPsn_Vendor_Zend_Translate * @throws IfwPsn_Vendor_Zend_Application_Resource_Exception if registry key was used * already but is no instance of IfwPsn_Vendor_Zend_Translate */ public function getTranslate() { if (null === $this->_translate) { $options = $this->getOptions(); if (!isset($options['content']) && !isset($options['data'])) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Application/Resource/Exception.php'; throw new IfwPsn_Vendor_Zend_Application_Resource_Exception('No translation source data provided.'); } else { if (array_key_exists('content', $options) && array_key_exists('data', $options)) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Application/Resource/Exception.php'; throw new IfwPsn_Vendor_Zend_Application_Resource_Exception('Conflict on translation source data: choose only one key between content and data.'); } } if (empty($options['adapter'])) { $options['adapter'] = IfwPsn_Vendor_Zend_Translate::AN_ARRAY; } if (!empty($options['data'])) { $options['content'] = $options['data']; unset($options['data']); } if (isset($options['log'])) { if (is_array($options['log'])) { $log = IfwPsn_Vendor_Zend_Log::factory($options['log']); } if ($log instanceof IfwPsn_Vendor_Zend_Log) { $options['log'] = $log; } } 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 IfwPsn_Vendor_Zend_Application_Bootstrap_ResourceBootstrapper && $bootstrap->hasPluginResource('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 (IfwPsn_Vendor_Zend_Registry::isRegistered($key)) { $translate = IfwPsn_Vendor_Zend_Registry::get($key); if (!$translate instanceof IfwPsn_Vendor_Zend_Translate) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Application/Resource/Exception.php'; throw new IfwPsn_Vendor_Zend_Application_Resource_Exception($key . ' already registered in registry but is ' . 'no instance of IfwPsn_Vendor_Zend_Translate'); } $translate->addTranslation($options); $this->_translate = $translate; } else { $this->_translate = new IfwPsn_Vendor_Zend_Translate($options); IfwPsn_Vendor_Zend_Registry::set($key, $this->_translate); } } return $this->_translate; }
/** * Return translation object * * @return IfwPsn_Vendor_Zend_Translate_Adapter|null */ public function getTranslator() { if ($this->translatorIsDisabled()) { return null; } if ($this->_translator === null) { require_once IFW_PSN_LIB_ROOT . 'IfwPsn/Vendor/Zend/Registry.php'; if (IfwPsn_Vendor_Zend_Registry::isRegistered('IfwPsn_Vendor_Zend_Translate')) { $translator = IfwPsn_Vendor_Zend_Registry::get('IfwPsn_Vendor_Zend_Translate'); if ($translator instanceof IfwPsn_Vendor_Zend_Translate_Adapter) { return $translator; } elseif ($translator instanceof IfwPsn_Vendor_Zend_Translate) { return $translator->getAdapter(); } } } return $this->_translator; }