本文整理汇总了PHP中Zend_Locale_Format::setOptions方法的典型用法代码示例。如果您正苦于以下问题:PHP Zend_Locale_Format::setOptions方法的具体用法?PHP Zend_Locale_Format::setOptions怎么用?PHP Zend_Locale_Format::setOptions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Zend_Locale_Format
的用法示例。
在下文中一共展示了Zend_Locale_Format::setOptions方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: startLocale
protected function startLocale()
{
require_once "Zend/Translate.php";
// silenciando strict até arrumar zend_locale
date_default_timezone_set("America/Sao_Paulo");
$i18n = new Zend_Translate('gettext', $this->config->system->path->base . '/lang/pt_BR.mo', 'pt_BR');
Zend_Registry::set('i18n', $i18n);
$translation_files = $this->config->system->path->base . "/lang/";
foreach (scandir($translation_files) as $filename) {
// Todos os arquivos .php devem ser classes de descrição de modulos
if (preg_match("/.*\\.mo\$/", $filename)) {
$translation_id = basename($filename, '.mo');
if ($translation_id != "pt_BR") {
$i18n->addTranslation($translation_files . "/{$filename}", $translation_id);
}
}
}
require_once "Zend/Locale.php";
if (Zend_Locale::isLocale($this->config->system->locale)) {
$locale = $this->config->system->locale;
} else {
$locale = "pt_BR";
}
Zend_Registry::set('Zend_Locale', new Zend_Locale($locale));
Zend_Locale::setDefault($locale);
Zend_Locale_Format::setOptions(array("locale" => $locale));
$i18n->setLocale($locale);
Zend_Registry::set("Zend_Translate", $i18n);
$zend_validate_translator = new Zend_Translate_Adapter_Array($this->config->system->path->base . "/lang/Zend_Validate/{$locale}/Zend_Validate.php", $locale);
Zend_Validate_Abstract::setDefaultTranslator($zend_validate_translator);
}
示例2: getLocale
/**
* Retrieves the locale object
*
* @return Zend_Locale
* @throws Glitch_Application_Resource_Exception
*/
public function getLocale()
{
if (null === $this->_locale) {
$options = $this->getOptions();
// Force these options to be set - don't rely on the defaults!
if (!isset($options['default'])) {
throw new Glitch_Application_Resource_Exception('Locale option "default" not set');
}
// First init cache, then create the locale
$this->_setCache();
$this->_locale = new Zend_Locale($options['default']);
Zend_Locale::setDefault($this->_locale);
// Allow application-wide access; e.g. Zend_Date uses this
Glitch_Registry::setLocale($this->_locale);
// Force formatter to use the above registered default locale
Zend_Locale_Format::setOptions(array('locale' => null));
}
return $this->_locale;
}
示例3: testSetOption
/**
* test setOption
* expected boolean
*/
public function testSetOption()
{
$this->assertEquals(7, count(Zend_Locale_Format::setOptions(array('format_type' => 'php'))));
$this->assertTrue(is_array(Zend_Locale_Format::setOptions()));
try {
$this->assertTrue(Zend_Locale_Format::setOptions(array('format_type' => 'xxx')));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$this->assertTrue(Zend_Locale_Format::setOptions(array('myformat' => 'xxx')));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$format = Zend_Locale_Format::setOptions(array('locale' => 'de', 'number_format' => Zend_Locale_Format::STANDARD));
$test = Zend_Locale_Data::getContent('de', 'decimalnumberformat');
$this->assertEquals($test['default'], $format['number_format']);
try {
$this->assertFalse(Zend_Locale_Format::setOptions(array('number_format' => array('x' => 'x'))));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$format = Zend_Locale_Format::setOptions(array('locale' => 'de', 'date_format' => Zend_Locale_Format::STANDARD));
$test = Zend_Locale_Format::getDateFormat('de');
$this->assertEquals($test, $format['date_format']);
try {
$this->assertFalse(Zend_Locale_Format::setOptions(array('date_format' => array('x' => 'x'))));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('fix_date' => 'no'))));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
$format = Zend_Locale_Format::setOptions(array('locale' => Zend_Locale_Format::STANDARD));
$locale = new Zend_Locale();
$this->assertEquals($locale, $format['locale']);
try {
$this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('locale' => 'nolocale'))));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('precision' => 50))));
$this->fail("exception expected");
} catch (Zend_Locale_Exception $e) {
// success
}
// test interaction between class-wide default date format and using locale's default format
try {
$result = array('date_format' => 'MMM d, yyyy', 'locale' => 'en_US', 'month' => '07',
'day' => '4', 'year' => '2007');
Zend_Locale_Format::setOptions(array('format_type' => 'iso', 'date_format' => 'MMM d, yyyy', 'locale' => 'en_US')); // test setUp
} catch (Zend_Locale_Exception $e) {
$this->fail("exception expected");
}
try {
// uses global date_format with global locale
$this->assertSame($result, Zend_Locale_Format::getDate('July 4, 2007'));
} catch (Zend_Locale_Exception $e) {
$this->fail("exception expected");
}
try {
// uses global date_format with given locale
$this->assertSame($result, Zend_Locale_Format::getDate('July 4, 2007', array('locale' => 'en_US')));
} catch (Zend_Locale_Exception $e) {
$this->fail("exception expected");
}
try {
// sets a new global date format
Zend_Locale_Format::setOptions(array('date_format' => 'M-d-y'));
} catch (Zend_Locale_Exception $e) {
$this->fail("exception expected");
}
try {
// uses global date format with given locale
// but this date format differs from the original set... (MMMM d, yyyy != M-d-y)
$expected = Zend_Locale_Format::getDate('July 4, 2007', array('locale' => 'en_US'));
$this->assertSame($expected['year'], $result['year'] );
$this->assertSame($expected['month'], $result['month']);
$this->assertSame($expected['day'], $result['day'] );
} catch (Zend_Locale_Exception $e) {
//.........这里部分代码省略.........
示例4: testCheckDateFormatDoesNotEmitNoticeWhenNoOptionsAreNotProvided
/**
* @group ZF-11837
*/
public function testCheckDateFormatDoesNotEmitNoticeWhenNoOptionsAreNotProvided()
{
try {
setlocale(LC_ALL, 'en_US');
// test setup
Zend_Locale_Format::setOptions(array('date_format' => 'yyyy-MM-dd'));
$this->assertTrue(Zend_Locale_Format::checkDateFormat('2011-10-21', array()));
} catch (PHPUnit_Framework_Error_Notice $ex) {
$this->fail('Zend_Locale_Format::checkDateFormat emitted unexpected E_NOTICE');
}
}
示例5: initLocale
//.........这里部分代码省略.........
Zend_Locale::setDefault('en_US');
} else {
$possibleLang = array();
if ($di->config->get('lang.display_choice')) {
$auth = $di->auth;
$user = $auth->getUserId() ? $auth->getUser() : null;
if (!empty($_REQUEST['_lang'])) {
$possibleLang[] = filterId($_REQUEST['_lang']);
} elseif (!empty($di->session->lang)) {
$possibleLang[] = $di->session->lang;
} elseif ($user && $user->lang) {
$possibleLang[] = $user->lang;
}
$br = Zend_Locale::getBrowser();
arsort($br);
$possibleLang = array_merge($possibleLang, array_keys($br));
}
$possibleLang[] = $di->config->get('lang.default', 'en_US');
$possibleLang[] = 'en_US';
// last but not least
// now choose the best candidate
$enabledLangs = $di->config->get('lang.enabled', array());
$checked = array();
foreach ($possibleLang as $lc) {
list($lang) = explode('_', $lc, 2);
if (!in_array($lc, $enabledLangs) && !in_array($lang, $enabledLangs)) {
continue;
}
if ($lc == $lang) {
// we have not got entire locale,guess it
if ($lc == 'en') {
$lc = 'en_US';
} elseif ($lc == 'sv') {
$lc = 'sv_SE';
} elseif ($lc == 'et') {
$lc = 'et_EE';
} elseif ($lc == 'vi') {
$lc = 'vi_VN';
} else {
$lc = Zend_Locale::getLocaleToTerritory($lang);
}
if (!$lc && $lang == 'ko') {
$lc = 'ko_KR';
}
if (!$lc && $lang == 'ja') {
$lc = 'ja_JP';
}
if (!$lc && $lang == 'nb') {
$lc = 'nb_NO';
}
if (!$lc && $lang == 'zh') {
$lc = 'zh_Hans';
}
if (!$lc && $lang == 'el') {
$lc = 'el_GR';
}
if (!$lc && $lang == 'he') {
$lc = 'he_IL';
}
if (!$lc && $lang == 'da') {
$lc = 'da_DK';
}
if (!$lc && $lang == 'cs') {
$lc = 'cs_CZ';
}
if (!$lc && $lang == 'sq') {
$lc = 'sq_AL';
}
if (!$lc) {
continue;
}
}
if (isset($checked[$lc])) {
continue;
}
$checked[$lc] = true;
// check if locale file is exists
$lc = preg_replace('/[^A-Za-z0-9_]/', '', $lc);
if (!Zend_Locale::isLocale($lc)) {
continue;
}
Zend_Locale::setDefault($lc);
// then update user if it was request
// and set to session
break;
}
if ($di->config->get('lang.display_choice') && !empty($_REQUEST['_lang'])) {
if (($_REQUEST['_lang'] == $lang || $_REQUEST['_lang'] == $lc) && $user && $user->lang != $lang) {
$user->updateQuick('lang', $lc);
}
// set to session
$di->session->lang = $lc;
}
}
Zend_Registry::set('Zend_Locale', new Zend_Locale());
$amLocale = new Am_Locale();
Zend_Registry::set('Am_Locale', $amLocale);
$di->locale = $amLocale;
Zend_Locale_Format::setOptions(array('date_format' => $amLocale->getDateFormat()));
}
示例6: testSetOption
/**
* test setOption
* expected boolean
*/
public function testSetOption()
{
$this->assertEquals(count(Zend_Locale_Format::setOptions(array('format_type' => 'php'))), 6);
$this->assertTrue(is_array(Zend_Locale_Format::setOptions()));
try {
$this->assertTrue(Zend_Locale_Format::setOptions(array('format_type' => 'xxx')));
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$this->assertTrue(Zend_Locale_Format::setOptions(array('myformat' => 'xxx')));
} catch (Zend_Locale_Exception $e) {
// success
}
$format = Zend_Locale_Format::setOptions(array('locale' => 'de', 'number_format' => Zend_Locale_Format::STANDARD));
$test = Zend_Locale_Data::getContent('de', 'decimalnumberformat');
$this->assertEquals($format['number_format'], $test['default']);
try {
$this->assertFalse(Zend_Locale_Format::setOptions(array('number_format' => array('x' => 'x'))));
$this->fail();
} catch (Zend_Locale_Exception $e) {
// success
}
$format = Zend_Locale_Format::setOptions(array('locale' => 'de', 'date_format' => Zend_Locale_Format::STANDARD));
$test = Zend_Locale_Format::getDateFormat('de');
$this->assertEquals($format['date_format'], $test);
try {
$this->assertFalse(Zend_Locale_Format::setOptions(array('date_format' => array('x' => 'x'))));
$this->fail();
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('fix_date' => 'no'))));
$this->fail();
} catch (Zend_Locale_Exception $e) {
// success
}
$format = Zend_Locale_Format::setOptions(array('locale' => Zend_Locale_Format::STANDARD));
$locale = new Zend_Locale();
$this->assertEquals($format['locale'], $locale);
try {
$this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('locale' => 'nolocale'))));
$this->fail();
} catch (Zend_Locale_Exception $e) {
// success
}
try {
$this->assertFalse(is_array(Zend_Locale_Format::setOptions(array('precision' => 50))));
$this->fail();
} catch (Zend_Locale_Exception $e) {
// success
}
}
示例7: __construct
public function __construct()
{
$config = Snep_Config::getConfig();
$locale = $this->locale = $config->system->locale;
$language = $this->language = $config->system->language;
$timezone = $this->timezone = $config->system->timezone;
if (!Zend_Locale::isLocale($locale)) {
throw new Exception("Fatal: '{$locale}' is not a valid locale", 500);
}
setlocale(LC_COLLATE, $locale . ".utf8");
Zend_Locale::setDefault($locale);
$this->zendLocale = $zendLocale = new Zend_Locale($locale);
Zend_Registry::set('Zend_Locale', $zendLocale);
Zend_Locale_Format::setOptions(array("locale" => $locale));
if (!Zend_Locale::isLocale($language)) {
throw new Exception("Fatal: '{$language}' is not a valid language locale", 500);
}
if (!self::isTimezone($timezone)) {
throw new Exception("Fatal: '{$timezone}' is not a valid timezone", 500);
}
date_default_timezone_set($timezone);
$language_alt = substr($language, 0, strpos($language, "_"));
if (file_exists(TRANSLATIONS_PATH . DIRECTORY_SEPARATOR . "{$language}.mo")) {
$translate = new Zend_Translate('gettext', TRANSLATIONS_PATH . DIRECTORY_SEPARATOR . "{$language}.mo", $language);
} else {
if (file_exists(TRANSLATIONS_PATH . DIRECTORY_SEPARATOR . "{$language_alt}.mo")) {
$translate = new Zend_Translate('gettext', TRANSLATIONS_PATH . DIRECTORY_SEPARATOR . "{$language_alt}.mo", $language);
} else {
$translate = new Zend_Translate('gettext', null, $language);
}
}
$this->zendTranslate = $translate;
Zend_Registry::set("Zend_Translate", $translate);
$lang_dirs = scandir(TRANSLATIONS_PATH . "/Zend_Validate/");
if (in_array($language, $lang_dirs)) {
$validate_locale = $language;
} else {
if (in_array($language_alt, $lang_dirs)) {
$validate_locale = $language_alt;
} else {
$validate_locale = "us";
}
}
$zend_validate_translator = new Zend_Translate_Adapter_Array(TRANSLATIONS_PATH . "/Zend_Validate/{$validate_locale}/Zend_Validate.php", $language);
Zend_Validate_Abstract::setDefaultTranslator($zend_validate_translator);
}
示例8: defined
<?php
/**
* Bootstrap para os testes do PHPUnit
*
* @link http://github.com/realejo/libraray-zf1
* @copyright Copyright (c) 2014 Realejo (http://realejo.com.br)
* @license http://unlicense.org
*/
// Define path to application directory
defined('TEST_ROOT') || define('TEST_ROOT', realpath(__DIR__));
// Define application environment
define('APPLICATION_ENV', 'testing');
if (getenv('TRAVIS') !== false) {
define('MARCA', 'travis');
}
require_once __DIR__ . '/../vendor/autoload.php';
require_once 'library/TestAssets/BaseTestCase.php';
Zend_Loader_Autoloader::getInstance();
$locale = new Zend_Locale('pt_BR');
Zend_Locale_Format::setOptions(array('precision' => 2));
Zend_Registry::set('Zend_Locale', $locale);
date_default_timezone_set("America/Sao_Paulo");