Procházet zdrojové kódy

Fix: boolean config options cannot be set to false in XML mappping

mgiagnoni před 12 roky
rodič
revize
d266d5403d

+ 14 - 1
lib/Gedmo/Mapping/Driver/Xml.php

@@ -45,6 +45,19 @@ abstract class Xml extends File
         return (string)$attributes[$attributeName];
     }
 
+    /**
+     * Get boolean attribute value.
+     * As we are supporting namespaces the only way to get to the attributes under a node is to use attributes function on it
+     *
+     * @param SimpleXMLElement $node
+     * @param  $attributeName
+     * @return boolean
+     */
+    protected function _getBooleanAttribute(SimpleXmlElement $node, $attributeName)
+    {
+        return 'true' === strtolower($this->_getAttribute($node, $attributeName));
+    }
+
     /**
      * does attribute exist under a specific node
      * As we are supporting namespaces the only way to get to the attributes under a node is to use attributes function on it
@@ -82,4 +95,4 @@ abstract class Xml extends File
         }
         return $result;
     }
-}
+}

+ 2 - 2
lib/Gedmo/Sluggable/Mapping/Driver/Xml.php

@@ -77,9 +77,9 @@ class Xml extends BaseXml
                         'style' => $this->_isAttributeSet($slug, 'style') ?
                             $this->_getAttribute($slug, 'style') : 'default',
                         'updatable' => $this->_isAttributeSet($slug, 'updatable') ?
-                            (bool)$this->_getAttribute($slug, 'updatable') : true,
+                            $this->_getBooleanAttribute($slug, 'updatable') : true,
                         'unique' => $this->_isAttributeSet($slug, 'unique') ?
-                            (bool)$this->_getAttribute($slug, 'unique') : true,
+                            $this->_getBooleanAttribute($slug, 'unique') : true,
                         'separator' => $this->_isAttributeSet($slug, 'separator') ?
                             $this->_getAttribute($slug, 'separator') : '-',
                     );

+ 1 - 1
tests/Gedmo/Mapping/Xml/SluggableMappingTest.php

@@ -64,7 +64,7 @@ class SluggableMappingTest extends BaseTestCaseORM
         $this->assertArrayHasKey('style', $config);
         $this->assertEquals('camel', $config['style']);
         $this->assertArrayHasKey('updatable', $config);
-        $this->assertTrue($config['updatable']);
+        $this->assertFalse($config['updatable']);
         $this->assertArrayHasKey('unique', $config);
         $this->assertTrue($config['unique']);
         $this->assertArrayHasKey('separator', $config);