diff --git a/library/log4php/configurators/LoggerConfigurationAdapterPHP.php b/library/log4php/configurators/LoggerConfigurationAdapterPHP.php new file mode 100644 --- /dev/null +++ b/library/log4php/configurators/LoggerConfigurationAdapterPHP.php @@ -0,0 +1,83 @@ + + * array( + * 'level' => 'info', + * 'appenders' => array('default') + * ), + * 'appenders' => array( + * 'default' => array( + * 'class' => 'LoggerAppenderEcho', + * 'layout' => array( + * 'class' => 'LoggerLayoutSimple' + * ) + * ) + * ) + * ) + * ?> + * + * + * @package log4php + * @subpackage configurators + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 + * @version $Revision: 1343601 $ + * @since 2.2 + */ +class LoggerConfigurationAdapterPHP implements LoggerConfigurationAdapter { + public function convert($url) { + if (!file_exists($url)) { + throw new LoggerException("File [$url] does not exist."); + } + + // Load the config file + $data = @file_get_contents($url); + if ($data === false) { + $error = error_get_last(); + throw new LoggerException("Error loading config file: {$error['message']}"); + } + + $config = @eval('?>' . $data); + + if ($config === false) { + $error = error_get_last(); + throw new LoggerException("Error parsing configuration: " . $error['message']); + } + + if (empty($config)) { + throw new LoggerException("Invalid configuration: empty configuration array."); + } + + if (!is_array($config)) { + throw new LoggerException("Invalid configuration: not an array."); + } + + return $config; + } +} +