Author: ihabunek
Date: Sat Aug 18 16:00:30 2012
New Revision: 1374601

URL: http://svn.apache.org/viewvc?rev=1374601&view=rev
Log:
LoggerConfigurationAdapterXML: Added parsing of <appender-ref> nodes, as well 
as <appender_ref> in loggers for backward compatibility.

Modified:
    
logging/log4php/trunk/src/main/php/configurators/LoggerConfigurationAdapterXML.php
    
logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php

Modified: 
logging/log4php/trunk/src/main/php/configurators/LoggerConfigurationAdapterXML.php
URL: 
http://svn.apache.org/viewvc/logging/log4php/trunk/src/main/php/configurators/LoggerConfigurationAdapterXML.php?rev=1374601&r1=1374600&r2=1374601&view=diff
==============================================================================
--- 
logging/log4php/trunk/src/main/php/configurators/LoggerConfigurationAdapterXML.php
 (original)
+++ 
logging/log4php/trunk/src/main/php/configurators/LoggerConfigurationAdapterXML.php
 Sat Aug 18 16:00:30 2012
@@ -173,10 +173,7 @@ class LoggerConfigurationAdapterXML impl
                        $logger['level'] = 
$this->getAttributeValue($node->level, 'value');
                }
                
-               $logger['appenders'] = array();
-               foreach($node->appender_ref as $appender) {
-                       $logger['appenders'][] = 
$this->getAttributeValue($appender, 'ref');
-               }
+               $logger['appenders'] = $this->parseAppenderReferences($node);
                
                $this->config['rootLogger'] = $logger;
        }
@@ -199,7 +196,7 @@ class LoggerConfigurationAdapterXML impl
                        $logger['additivity'] = $this->getAttributeValue($node, 
'additivity');
                }
                
-               $logger['appenders'] = $this->parseAppenderReferences($node, 
$name);
+               $logger['appenders'] = $this->parseAppenderReferences($node);
 
                // Check for duplicate loggers
                if (isset($this->config['loggers'][$name])) {
@@ -211,13 +208,20 @@ class LoggerConfigurationAdapterXML impl
        
        /** 
         * Parses a <logger> node for appender references and returns them in 
an array.
+        * 
+        * Previous versions supported appender-ref, as well as appender_ref so 
both
+        * are parsed for backward compatibility.
         */
-       private function parseAppenderReferences(SimpleXMLElement $node, $name) 
{
+       private function parseAppenderReferences(SimpleXMLElement $node) {
                $refs = array();
                foreach($node->appender_ref as $ref) {
                        $refs[] = $this->getAttributeValue($ref, 'ref');
                }
                
+               foreach($node->{'appender-ref'} as $ref) {
+                       $refs[] = $this->getAttributeValue($ref, 'ref');
+               }
+
                return $refs;
        }
        

Modified: 
logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php
URL: 
http://svn.apache.org/viewvc/logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php?rev=1374601&r1=1374600&r2=1374601&view=diff
==============================================================================
--- 
logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php
 (original)
+++ 
logging/log4php/trunk/src/test/php/configurators/LoggerConfigurationAdapterXMLTest.php
 Sat Aug 18 16:00:30 2012
@@ -114,6 +114,14 @@ class LoggerConfigurationAdapterXMLTest 
                $this->assertEquals($this->expected1, $actual);
        }
        
+       public function testConversion2() {
+               $url =  PHPUNIT_CONFIG_DIR . 
'/adapters/xml/config_valid_underscore.xml';
+               $adapter = new LoggerConfigurationAdapterXML();
+               $actual = $adapter->convert($url);
+               
+               $this->assertEquals($this->expected1, $actual);
+       }
+       
        /**
         * Test exception is thrown when file cannot be found.
         * @expectedException LoggerException


Reply via email to