Procházet zdrojové kódy

ZF-11384
Zend_Config
Added support for indented comments in Zend_Config_Yaml


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

adamlundrigan před 14 roky
rodič
revize
6f18bb6803
2 změnil soubory, kde provedl 23 přidání a 4 odebrání
  1. 3 4
      library/Zend/Config/Yaml.php
  2. 20 0
      tests/Zend/Config/YamlTest.php

+ 3 - 4
library/Zend/Config/Yaml.php

@@ -285,13 +285,12 @@ class Zend_Config_Yaml extends Zend_Config
         $inIndent = false;
         while (list($n, $line) = each($lines)) {
             $lineno = $n + 1;
+            
+            $line = rtrim(preg_replace("/#.*$/", "", $line));
             if (strlen($line) == 0) {
                 continue;
             }
-            if ($line[0] == '#') {
-                // comment
-                continue;
-            }
+
             $indent = strspn($line, " ");
 
             // line without the spaces

+ 20 - 0
tests/Zend/Config/YamlTest.php

@@ -47,6 +47,7 @@ class Zend_Config_YamlTest extends PHPUnit_Framework_TestCase
         $this->_booleansConfig            = dirname(__FILE__) . '/_files/booleans.yaml';
         $this->_constantsConfig           = dirname(__FILE__) . '/_files/constants.yaml';
         $this->_yamlInlineCommentsConfig  = dirname(__FILE__) . '/_files/inlinecomments.yaml';
+        $this->_yamlIndentedCommentsConfig  = dirname(__FILE__) . '/_files/indentedcomments.yaml';
     }
 
     public function testLoadSingleSection()
@@ -334,4 +335,23 @@ class Zend_Config_YamlTest extends PHPUnit_Framework_TestCase
             $config->resources->frontController->controllerDirectory
         );
     }
+    
+    /**
+     * @group ZF-11384
+     */
+    public function testAllowsIndentedCommentsUsingHash()
+    {
+        $config = new Zend_Config_Yaml($this->_yamlIndentedCommentsConfig, null);
+        $this->assertType('Zend_Config', $config->resources);
+        $this->assertType('Zend_Config', $config->resources->frontController);
+        $this->assertType(
+            'string', 
+            $config->resources->frontController->controllerDirectory
+        );
+        $this->assertSame(
+            'APPLICATION_PATH/controllers',
+            $config->resources->frontController->controllerDirectory
+        );
+    }
+    
 }