From 4f1d81e6fde4f3f8d9876ad176ba8acd6c058268 Mon Sep 17 00:00:00 2001 From: meadsteve Date: Thu, 28 Nov 2013 21:04:27 +0000 Subject: [PATCH] update loggerConfig constructor to take array by default to make unit testing simpler. --- PHPCI/Helper/LoggerConfig.php | 29 +++++++++++++++++++++-------- console | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/PHPCI/Helper/LoggerConfig.php b/PHPCI/Helper/LoggerConfig.php index 014805f2..1e130e1a 100644 --- a/PHPCI/Helper/LoggerConfig.php +++ b/PHPCI/Helper/LoggerConfig.php @@ -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; } /** diff --git a/console b/console index 3358dce7..baa0e13a 100644 --- a/console +++ b/console @@ -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();