Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
70.00% |
21 / 30 |
|
50.00% |
3 / 6 |
CRAP | |
0.00% |
0 / 1 |
| common_log_Dispatcher | |
70.00% |
21 / 30 |
|
50.00% |
3 / 6 |
28.75 | |
0.00% |
0 / 1 |
| log | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| getLogThreshold | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| init | |
100.00% |
14 / 14 |
|
100.00% |
1 / 1 |
8 | |||
| singleton | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| __construct | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
3.33 | |||
| addAppender | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2002-2008 (original work) Public Research Centre Henri Tudor & University of Luxembourg |
| 19 | * (under the project TAO & TAO2); |
| 20 | * 2008-2010 (update and modification) Deutsche Institut für Internationale Pädagogische Forschung |
| 21 | * (under the project TAO-TRANSFER); |
| 22 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 23 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | /** |
| 28 | * Short description of class common_log_Dispatcher |
| 29 | * |
| 30 | * @access public |
| 31 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 32 | * @package generis |
| 33 | |
| 34 | */ |
| 35 | class common_log_Dispatcher implements common_log_Appender |
| 36 | { |
| 37 | /** |
| 38 | * Identifer of the configuration that stores the log configuration |
| 39 | * |
| 40 | * @var string |
| 41 | */ |
| 42 | public const CONFIG_ID = 'log'; |
| 43 | |
| 44 | // --- ATTRIBUTES --- |
| 45 | |
| 46 | /** |
| 47 | * Short description of attribute appenders |
| 48 | * |
| 49 | * @access private |
| 50 | * @var array |
| 51 | */ |
| 52 | private $appenders = []; |
| 53 | |
| 54 | /** |
| 55 | * Short description of attribute minLevel |
| 56 | * |
| 57 | * @access private |
| 58 | * @var int |
| 59 | */ |
| 60 | private $minLevel = null; |
| 61 | |
| 62 | /** |
| 63 | * Short description of attribute instance |
| 64 | * |
| 65 | * @access private |
| 66 | * @var Dispatcher |
| 67 | */ |
| 68 | private static $instance = null; |
| 69 | |
| 70 | // --- OPERATIONS --- |
| 71 | |
| 72 | /** |
| 73 | * Short description of method log |
| 74 | * |
| 75 | * @access public |
| 76 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 77 | * @param Item item |
| 78 | * @return mixed |
| 79 | */ |
| 80 | public function log(common_log_Item $item) |
| 81 | { |
| 82 | foreach ($this->appenders as $appender) { |
| 83 | $appender->log($item); |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Short description of method getLogThreshold |
| 89 | * |
| 90 | * @access public |
| 91 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 92 | * @return int |
| 93 | */ |
| 94 | public function getLogThreshold() |
| 95 | { |
| 96 | $returnValue = (int) 0; |
| 97 | |
| 98 | |
| 99 | $returnValue = $this->minLevel; |
| 100 | |
| 101 | |
| 102 | return (int) $returnValue; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Short description of method init |
| 107 | * |
| 108 | * @access public |
| 109 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 110 | * @param array configuration |
| 111 | * @return boolean |
| 112 | */ |
| 113 | public function init($configuration) |
| 114 | { |
| 115 | $returnValue = (bool) false; |
| 116 | |
| 117 | $this->appenders = []; |
| 118 | $this->minLevel = null; |
| 119 | foreach ($configuration as $appenderConfig) { |
| 120 | if (isset($appenderConfig['class'])) { |
| 121 | $classname = $appenderConfig['class']; |
| 122 | if (!class_exists($classname)) { |
| 123 | $classname = 'common_log_' . $classname; |
| 124 | } |
| 125 | if (class_exists($classname) && is_subclass_of($classname, 'common_log_Appender')) { |
| 126 | $appender = new $classname(); |
| 127 | if (!is_null($appender) && $appender->init($appenderConfig)) { |
| 128 | $this->addAppender($appender); |
| 129 | } |
| 130 | } |
| 131 | } |
| 132 | } |
| 133 | $returnValue = (count($this->appenders) > 0); |
| 134 | |
| 135 | |
| 136 | return (bool) $returnValue; |
| 137 | } |
| 138 | |
| 139 | /** |
| 140 | * Short description of method singleton |
| 141 | * |
| 142 | * @access public |
| 143 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 144 | * @return common_log_Dispatcher |
| 145 | */ |
| 146 | public static function singleton() |
| 147 | { |
| 148 | $returnValue = null; |
| 149 | |
| 150 | |
| 151 | if (is_null(self::$instance)) { |
| 152 | self::$instance = new common_log_Dispatcher(); |
| 153 | } |
| 154 | $returnValue = self::$instance; |
| 155 | |
| 156 | |
| 157 | return $returnValue; |
| 158 | } |
| 159 | |
| 160 | /** |
| 161 | * Short description of method __construct |
| 162 | * |
| 163 | * @access private |
| 164 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 165 | * @return mixed |
| 166 | */ |
| 167 | public function __construct($config = null) |
| 168 | { |
| 169 | if (is_null($config) || !is_array($config)) { |
| 170 | $config = []; |
| 171 | } |
| 172 | $this->init($config); |
| 173 | } |
| 174 | |
| 175 | /** |
| 176 | * Short description of method addAppender |
| 177 | * |
| 178 | * @access public |
| 179 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 180 | * @param Appender appender |
| 181 | * @return mixed |
| 182 | */ |
| 183 | public function addAppender(common_log_Appender $appender) |
| 184 | { |
| 185 | |
| 186 | $this->appenders[] = $appender; |
| 187 | if (is_null($this->minLevel) || $this->minLevel > $appender->getLogThreshold()) { |
| 188 | $this->minLevel = $appender->getLogThreshold(); |
| 189 | } |
| 190 | } |
| 191 | } |