Explorar o código

ZF-10898 - Added support to Zend_Application to load a production (version controlled) application configuration file by default (e.g. application.ini.dist).


git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@23842 44c647ce-9c0f-0410-b52a-842ac1e357ba
wilmoore %!s(int64=14) %!d(string=hai) anos
pai
achega
1c77004949

+ 5 - 2
library/Zend/Application.php

@@ -376,9 +376,12 @@ class Zend_Application
     protected function _loadConfig($file)
     {
         $environment = $this->getEnvironment();
-        $suffix      = strtolower(pathinfo($file, PATHINFO_EXTENSION));
+        $suffix      = pathinfo($file, PATHINFO_EXTENSION);
+        $suffix      = ($suffix === 'dist')
+                     ? pathinfo(basename($file, ".$suffix"), PATHINFO_EXTENSION)
+                     : $suffix;
 
-        switch ($suffix) {
+        switch (strtolower($suffix)) {
             case 'ini':
                 $config = new Zend_Config_Ini($file, $environment);
                 break;

+ 19 - 0
tests/Zend/Application/ApplicationTest.php

@@ -285,6 +285,25 @@ class Zend_Application_ApplicationTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * @group ZF-10898
+     */
+    public function testPassingStringIniDistfileConfigPathOptionToConstructorShouldLoadOptions()
+    {
+        $application = new Zend_Application('testing', dirname(__FILE__) . '/_files/appconfig.ini.dist');
+        $this->assertTrue($application->hasOption('foo'));
+    }
+
+    /**
+     * @group ZF-10898
+     */
+    public function testPassingArrayOptionsWithConfigKeyDistfileShouldLoadOptions()
+    {
+        $application = new Zend_Application('testing', array('bar' => 'baz', 'config' => dirname(__FILE__) . '/_files/appconfig.ini.dist'));
+        $this->assertTrue($application->hasOption('foo'));
+        $this->assertTrue($application->hasOption('bar'));
+    }
+
+    /**
      * @group ZF-10568
      */
     public function testPassingStringYamlConfigPathOptionToConstructorShouldLoadOptions()

+ 5 - 0
tests/Zend/Application/_files/appconfig.ini.dist

@@ -0,0 +1,5 @@
+[production]
+foo = "bar"
+
+[testing : production]
+