當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Locale::toString方法代碼示例

本文整理匯總了PHP中Zend\Locale\Locale::toString方法的典型用法代碼示例。如果您正苦於以下問題:PHP Locale::toString方法的具體用法?PHP Locale::toString怎麽用?PHP Locale::toString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Zend\Locale\Locale的用法示例。


在下文中一共展示了Locale::toString方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testTerritoryToGetLocale

    /**
     * @ZF-9488
     */
    public function testTerritoryToGetLocale()
    {
        $value = Locale::findLocale('US');
        $this->assertEquals('en_US', $value);

        $value = new Locale('US');
        $this->assertEquals('en_US', $value->toString());

        $value = new Locale('TR');
        $this->assertEquals('tr_TR', $value->toString());
    }
開發者ID:niallmccrudden,項目名稱:zf2,代碼行數:14,代碼來源:LocaleTest.php

示例2: equals

 /**
  * Returns true if both locales are equal
  *
  * @param  \Zend\Locale\Locale $object Locale to check for equality
  * @return boolean
  */
 public function equals(Locale $object)
 {
     if ($object->toString() === $this->toString()) {
         return true;
     }
     return false;
 }
開發者ID:bradley-holt,項目名稱:zf2,代碼行數:13,代碼來源:Locale.php

示例3: testSetOption

 /**
  * test setOption
  * expected boolean
  */
 public function testSetOption()
 {
     $this->assertEquals(8, count(Format::setOptions(array('format_type' => 'php'))));
     $this->assertTrue(is_array(Format::setOptions()));
     try {
         $this->assertTrue(Format::setOptions(array('format_type' => 'xxx')));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     try {
         $this->assertTrue(Format::setOptions(array('myformat' => 'xxx')));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     $format = Format::setOptions(array('locale' => 'de', 'number_format' => Format::STANDARD));
     $test = Cldr::getContent('de', 'decimalnumber');
     $this->assertEquals($test, $format['number_format']);
     try {
         $this->assertFalse(Format::setOptions(array('number_format' => array('x' => 'x'))));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     $format = Format::setOptions(array('locale' => 'de', 'date_format' => Format::STANDARD));
     $test = Format::getDateFormat('de');
     $this->assertEquals($test, $format['date_format']);
     try {
         $this->assertFalse(Format::setOptions(array('date_format' => array('x' => 'x'))));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     try {
         $this->assertFalse(is_array(Format::setOptions(array('fix_date' => 'no'))));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     $format = Format::setOptions(array('locale' => Format::STANDARD));
     $locale = new Locale();
     $this->assertEquals($locale->toString(), $format['locale']);
     try {
         $this->assertFalse(is_array(Format::setOptions(array('locale' => 'nolocale'))));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     try {
         $this->assertFalse(is_array(Format::setOptions(array('precision' => 50))));
         $this->fail("exception expected");
     } catch (InvalidArgumentException $e) {
         // success
     }
     // test interaction between class-wide default date format and using locale's default format
     try {
         $result = array('date_format' => 'MMM d, y', 'locale' => 'en_US', 'month' => '7', 'day' => '4', 'year' => '2007');
         Format::setOptions(array('format_type' => 'iso', 'date_format' => 'MMM d, y', 'locale' => 'en_US'));
         // test setUp
     } catch (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     try {
         // uses global date_format with global locale
         $this->assertSame($result, Format::getDate('July 4, 2007'));
     } catch (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     try {
         // uses global date_format with given locale
         $this->assertSame($result, Format::getDate('July 4, 2007', array('locale' => 'en_US')));
     } catch (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     try {
         // sets a new global date format
         Format::setOptions(array('date_format' => 'M-d-y'));
     } catch (InvalidArgumentException $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 = 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 (InvalidArgumentException $e) {
         $this->fail("exception expected");
     }
     try {
         // the following should not be used... instead of null, Locale::ZFDEFAULT should be used
         // uses given local with standard format from this locale
         $this->assertSame($result, Format::getDate('July 4, 2007', array('locale' => 'en_US', 'date_format' => null)));
     } catch (InvalidArgumentException $e) {
//.........這裏部分代碼省略.........
開發者ID:alab1001101,項目名稱:zf2,代碼行數:101,代碼來源:FormatTest.php


注:本文中的Zend\Locale\Locale::toString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。