Kaynağa Gözat

ZF-8435 & ZF-6489 Added documentation on the Locale Resource Plugin
Reworked a bit on the Locale Resource Plugin


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@20040 44c647ce-9c0f-0410-b52a-842ac1e357ba

freak 16 yıl önce
ebeveyn
işleme
b89b914502

+ 41 - 0
documentation/manual/en/module_specs/Zend_Application-AvailableResources-Locale.xml

@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Reviewed: no -->
+<sect2 id="zend.application.available-resources.locale">
+    <title>Zend_Application_Resource_Locale</title>
+
+    <para>
+        <classname>Zend_Application_Resource_Locale</classname> can be used to
+        set an (application-wide) locale to use in classes that use localization.
+    </para>
+
+    <para>
+        There are basically three uses of the Locale Resource Plugin.
+        With one you don't specify any options for the Resource Plugin.
+        By doing so, <classname>Zend_Locale</classname> tries to determine
+        what locale to use, and that's it.
+    </para>
+    
+    <example id="zend.application.available-resources.locale.configExample">
+        <title>Sample Locale Resource Configuration</title>
+
+        <para>
+            For the other two uses, please see the code sample below.
+        </para>
+
+        <programlisting language="ini"><![CDATA[
+; No matter what, the nl_NL locale will be used.
+resources.locale.default = "nl_NL"
+resources.locale.force = true
+
+; Try to determine automatically first,
+; if unsuccessful, use nl_NL as fallback.
+resources.locale.default = "nl_NL"
+resources.locale.force = false
+]]></programlisting>
+
+        <para>
+            Please note that the last line could be left out, since the
+            force-directive defaults to false.
+        </para>
+    </example>
+</sect2>

+ 1 - 0
documentation/manual/en/module_specs/Zend_Application-AvailableResources.xml

@@ -12,6 +12,7 @@
     <xi:include href="Zend_Application-AvailableResources-Db.xml" />
     <xi:include href="Zend_Application-AvailableResources-Frontcontroller.xml" />
     <xi:include href="Zend_Application-AvailableResources-Layout.xml" />
+    <xi:include href="Zend_Application-AvailableResources-Locale.xml" />
     <xi:include href="Zend_Application-AvailableResources-Log.xml" />
     <xi:include href="Zend_Application-AvailableResources-Mail.xml" />
     <xi:include href="Zend_Application-AvailableResources-Modules.xml" />

+ 8 - 2
library/Zend/Application/Resource/Locale.php

@@ -60,10 +60,15 @@ class Zend_Application_Resource_Locale
     {
         if (null === $this->_locale) {
             $options = $this->getOptions();
-            if (!isset($options['default'])) {
+            if(!isset($options['default'])) {
                 $this->_locale = new Zend_Locale();
-            } else {
+            } elseif(!isset($options['force']) ||
+                     (bool) $options['force'] == false)
+            {
+                // Don't force any locale, just go for auto detection
                 Zend_Locale::setDefault($options['default']);
+                $this->_locale = new Zend_Locale();
+            } else {
                 $this->_locale = new Zend_Locale($options['default']);
             }
 
@@ -72,6 +77,7 @@ class Zend_Application_Resource_Locale
                 : self::DEFAULT_REGISTRY_KEY;
             Zend_Registry::set($key, $this->_locale);
         }
+
         return $this->_locale;
     }
 }

+ 17 - 0
tests/Zend/Application/Resource/LocaleTest.php

@@ -106,6 +106,7 @@ class Zend_Application_Resource_LocaleTest extends PHPUnit_Framework_TestCase
         $options = array(
             'default'      => 'kok_IN',
             'registry_key' => 'Foo_Bar',
+            'force'        => true
         );
 
         $resource = new Zend_Application_Resource_Locale($options);
@@ -116,6 +117,22 @@ class Zend_Application_Resource_LocaleTest extends PHPUnit_Framework_TestCase
         $this->assertTrue(Zend_Registry::isRegistered('Foo_Bar'));
         $this->assertSame(Zend_Registry::get('Foo_Bar'), $locale);
     }
+    
+    public function testOptionsPassedToResourceAreUsedToSetLocaleState1()
+    {
+        $options = array(
+            'default'      => 'kok_IN',
+        );
+
+        $resource = new Zend_Application_Resource_Locale($options);
+        $resource->setBootstrap($this->bootstrap);
+        $resource->init();
+        $locale   = $resource->getLocale();
+        
+        // This test will fail if your configured locale is kok_IN
+        $this->assertFalse('kok_IN' == $locale->__toString());
+        $this->assertSame(Zend_Registry::get('Zend_Locale'), $locale);
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_LocaleTest::main') {

+ 12 - 0
tests/Zend/Application/Resource/LogTest.php

@@ -127,6 +127,18 @@ class Zend_Application_Resource_LogTest extends PHPUnit_Framework_TestCase
         rewind($stream);
         $this->assertContains($message, stream_get_contents($stream));
     }
+    
+public function testNumericLogStreamFilterParamsPriorityDoesNotFail() {
+        $options = array('stream' =>
+                        array('writerName'   => 'Stream',
+                              'writerParams' => array('stream' => "php://memory",
+                                                      'mode' => 'a'),
+                        array('filterName' => 'Priority'),
+                        array('filterParams' => array('priority' => '4'))));
+        $resource = new Zend_Application_Resource_Log($options);
+        $resource->setBootstrap($this->bootstrap);
+        $resource->init();
+    }
 }
 
 if (PHPUnit_MAIN_METHOD == 'Zend_Application_Resource_LogTest::main') {