LoggerConfigurationAdapterXML: Added parsing of <appender-ref> nodes, as well as...
authorIvan Habunek <ihabunek@apache.org>
Sat, 18 Aug 2012 16:00:30 +0000 (16:00 +0000)
committerIvan Habunek <ihabunek@apache.org>
Sat, 18 Aug 2012 16:00:30 +0000 (16:00 +0000)
git-svn-id: https://svn.apache.org/repos/asf/logging/log4php/trunk@1374601 13f79535-47bb-0310-9956-ffa450edef68

src/main/php/configurators/LoggerConfigurationAdapterXML.php
src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php

index cfa725f..7ee6f6d 100644 (file)
@@ -173,10 +173,7 @@ class LoggerConfigurationAdapterXML implements LoggerConfigurationAdapter
                        $logger['level'] = $this->getAttributeValue($node->level, 'value');\r
                }\r
                \r
-               $logger['appenders'] = array();\r
-               foreach($node->appender_ref as $appender) {\r
-                       $logger['appenders'][] = $this->getAttributeValue($appender, 'ref');\r
-               }\r
+               $logger['appenders'] = $this->parseAppenderReferences($node);\r
                \r
                $this->config['rootLogger'] = $logger;\r
        }\r
@@ -199,7 +196,7 @@ class LoggerConfigurationAdapterXML implements LoggerConfigurationAdapter
                        $logger['additivity'] = $this->getAttributeValue($node, 'additivity');\r
                }\r
                \r
-               $logger['appenders'] = $this->parseAppenderReferences($node, $name);\r
+               $logger['appenders'] = $this->parseAppenderReferences($node);\r
 \r
                // Check for duplicate loggers\r
                if (isset($this->config['loggers'][$name])) {\r
@@ -211,13 +208,20 @@ class LoggerConfigurationAdapterXML implements LoggerConfigurationAdapter
        \r
        /** \r
         * Parses a <logger> node for appender references and returns them in an array.\r
+        * \r
+        * Previous versions supported appender-ref, as well as appender_ref so both\r
+        * are parsed for backward compatibility.\r
         */\r
-       private function parseAppenderReferences(SimpleXMLElement $node, $name) {\r
+       private function parseAppenderReferences(SimpleXMLElement $node) {\r
                $refs = array();\r
                foreach($node->appender_ref as $ref) {\r
                        $refs[] = $this->getAttributeValue($ref, 'ref');\r
                }\r
                \r
+               foreach($node->{'appender-ref'} as $ref) {\r
+                       $refs[] = $this->getAttributeValue($ref, 'ref');\r
+               }\r
+\r
                return $refs;\r
        }\r
        \r
index db3fe99..ff71ef1 100644 (file)
@@ -114,6 +114,14 @@ class LoggerConfigurationAdapterXMLTest extends PHPUnit_Framework_TestCase {
                $this->assertEquals($this->expected1, $actual);\r
        }\r
        \r
+       public function testConversion2() {\r
+               $url =  PHPUNIT_CONFIG_DIR . '/adapters/xml/config_valid_underscore.xml';\r
+               $adapter = new LoggerConfigurationAdapterXML();\r
+               $actual = $adapter->convert($url);\r
+               \r
+               $this->assertEquals($this->expected1, $actual);\r
+       }\r
+       \r
        /**\r
         * Test exception is thrown when file cannot be found.\r
         * @expectedException LoggerException\r