update loggerConfig constructor to take array by default to make unit testing simpler.

This commit is contained in:
meadsteve 2013-11-28 21:04:27 +00:00
parent 6d5bceea16
commit 4f1d81e6fd
2 changed files with 22 additions and 9 deletions

View file

@ -13,18 +13,31 @@ class LoggerConfig {
private $config;
/**
* The file specified is expected to return an array. Where each key
* is the name of a logger. The value of each key should be an array or
* a function that returns an array of LogHandlers.
* @param $logConfigFilePath
* The filepath is expected to return an array which will be
* passed to the normal constructor.
*
* @param string $filePath
* @return LoggerConfig
*/
function __construct($logConfigFilePath) {
if (file_exists($logConfigFilePath)) {
$this->config = require_once($logConfigFilePath);
public static function newFromFile($filePath)
{
if (file_exists($filePath)) {
$configArray = require($filePath);
}
else {
$this->config = array();
$configArray = array();
}
return new self($configArray);
}
/**
* Each key of the array is the name of a logger. The value of
* each key should be an array or a function that returns an
* array of LogHandlers.
* @param array $configArray
*/
function __construct(array $configArray = array()) {
$this->config = $configArray;
}
/**

View file

@ -20,7 +20,7 @@ use PHPCI\Command\DaemonCommand;
use PHPCI\Command\PollCommand;
use Symfony\Component\Console\Application;
$loggerConfig = new \PHPCI\Helper\LoggerConfig(__DIR__ . "/loggerconfig.php");
$loggerConfig = \PHPCI\Helper\LoggerConfig::newFromFile(__DIR__ . "/loggerconfig.php");
$application = new Application();