@@ -143,8 +143,8 @@ |
||
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
| 146 | - * @return string |
|
| 147 | - */ |
|
| 146 | + * @return string |
|
| 147 | + */ |
|
| 148 | 148 | public function getKey() |
| 149 | 149 | { |
| 150 | 150 | return $this->key; |
@@ -49,192 +49,192 @@ |
||
| 49 | 49 | */ |
| 50 | 50 | class Payone_Log4php_LoggerHierarchy { |
| 51 | 51 | |
| 52 | - /** Array holding all Logger instances. */ |
|
| 53 | - protected $loggers = array(); |
|
| 52 | + /** Array holding all Logger instances. */ |
|
| 53 | + protected $loggers = array(); |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * The root logger. |
|
| 57 | - * @var RootLogger |
|
| 58 | - */ |
|
| 59 | - protected $root = null; |
|
| 55 | + /** |
|
| 56 | + * The root logger. |
|
| 57 | + * @var RootLogger |
|
| 58 | + */ |
|
| 59 | + protected $root = null; |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * The logger renderer map. |
|
| 63 | - * @var Payone_Log4php_LoggerRendererMap |
|
| 64 | - */ |
|
| 65 | - protected $rendererMap; |
|
| 61 | + /** |
|
| 62 | + * The logger renderer map. |
|
| 63 | + * @var Payone_Log4php_LoggerRendererMap |
|
| 64 | + */ |
|
| 65 | + protected $rendererMap; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Main level threshold. Events with lower level will not be logged by any |
|
| 69 | - * logger, regardless of it's configuration. |
|
| 70 | - * @var Payone_Log4php_LoggerLevel |
|
| 71 | - */ |
|
| 72 | - protected $threshold; |
|
| 67 | + /** |
|
| 68 | + * Main level threshold. Events with lower level will not be logged by any |
|
| 69 | + * logger, regardless of it's configuration. |
|
| 70 | + * @var Payone_Log4php_LoggerLevel |
|
| 71 | + */ |
|
| 72 | + protected $threshold; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * Creates a new logger hierarchy. |
|
| 76 | - * @param Payone_Log4php_LoggerRoot $root The root logger. |
|
| 77 | - */ |
|
| 78 | - public function __construct(Payone_Log4php_LoggerRoot $root) { |
|
| 79 | - $this->root = $root; |
|
| 80 | - $this->setThreshold(Payone_Log4php_LoggerLevel::getLevelAll()); |
|
| 81 | - $this->rendererMap = new Payone_Log4php_LoggerRendererMap(); |
|
| 82 | - } |
|
| 74 | + /** |
|
| 75 | + * Creates a new logger hierarchy. |
|
| 76 | + * @param Payone_Log4php_LoggerRoot $root The root logger. |
|
| 77 | + */ |
|
| 78 | + public function __construct(Payone_Log4php_LoggerRoot $root) { |
|
| 79 | + $this->root = $root; |
|
| 80 | + $this->setThreshold(Payone_Log4php_LoggerLevel::getLevelAll()); |
|
| 81 | + $this->rendererMap = new Payone_Log4php_LoggerRendererMap(); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - /** |
|
| 85 | - * Clears all loggers. |
|
| 86 | - */ |
|
| 87 | - public function clear() { |
|
| 88 | - $this->loggers = array(); |
|
| 89 | - } |
|
| 84 | + /** |
|
| 85 | + * Clears all loggers. |
|
| 86 | + */ |
|
| 87 | + public function clear() { |
|
| 88 | + $this->loggers = array(); |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - /** |
|
| 92 | - * Check if the named logger exists in the hierarchy. |
|
| 93 | - * @param string $name |
|
| 94 | - * @return boolean |
|
| 95 | - */ |
|
| 96 | - public function exists($name) { |
|
| 97 | - return isset($this->loggers[$name]); |
|
| 98 | - } |
|
| 91 | + /** |
|
| 92 | + * Check if the named logger exists in the hierarchy. |
|
| 93 | + * @param string $name |
|
| 94 | + * @return boolean |
|
| 95 | + */ |
|
| 96 | + public function exists($name) { |
|
| 97 | + return isset($this->loggers[$name]); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Returns all the currently defined loggers in this hierarchy as an array. |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 104 | - public function getCurrentLoggers() { |
|
| 105 | - return array_values($this->loggers); |
|
| 106 | - } |
|
| 100 | + /** |
|
| 101 | + * Returns all the currently defined loggers in this hierarchy as an array. |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | + public function getCurrentLoggers() { |
|
| 105 | + return array_values($this->loggers); |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * Returns a named logger instance logger. If it doesn't exist, one is created. |
|
| 110 | - * |
|
| 111 | - * @param string $name Logger name |
|
| 112 | - * @return Logger Logger instance. |
|
| 113 | - */ |
|
| 114 | - public function getLogger($name) { |
|
| 115 | - if(!isset($this->loggers[$name])) { |
|
| 116 | - $logger = new Payone_Log4php_Logger($name); |
|
| 108 | + /** |
|
| 109 | + * Returns a named logger instance logger. If it doesn't exist, one is created. |
|
| 110 | + * |
|
| 111 | + * @param string $name Logger name |
|
| 112 | + * @return Logger Logger instance. |
|
| 113 | + */ |
|
| 114 | + public function getLogger($name) { |
|
| 115 | + if(!isset($this->loggers[$name])) { |
|
| 116 | + $logger = new Payone_Log4php_Logger($name); |
|
| 117 | 117 | |
| 118 | - $nodes = explode('.', $name); |
|
| 119 | - $firstNode = array_shift($nodes); |
|
| 118 | + $nodes = explode('.', $name); |
|
| 119 | + $firstNode = array_shift($nodes); |
|
| 120 | 120 | |
| 121 | - // if name is not a first node but another first node is their |
|
| 122 | - if($firstNode != $name and isset($this->loggers[$firstNode])) { |
|
| 123 | - $logger->setParent($this->loggers[$firstNode]); |
|
| 124 | - } else { |
|
| 125 | - // if there is no father, set root logger as father |
|
| 126 | - $logger->setParent($this->root); |
|
| 127 | - } |
|
| 121 | + // if name is not a first node but another first node is their |
|
| 122 | + if($firstNode != $name and isset($this->loggers[$firstNode])) { |
|
| 123 | + $logger->setParent($this->loggers[$firstNode]); |
|
| 124 | + } else { |
|
| 125 | + // if there is no father, set root logger as father |
|
| 126 | + $logger->setParent($this->root); |
|
| 127 | + } |
|
| 128 | 128 | |
| 129 | - // if there are more nodes than one |
|
| 130 | - if(count($nodes) > 0) { |
|
| 131 | - // find parent node |
|
| 132 | - foreach($nodes as $node) { |
|
| 133 | - $parentNode = "$firstNode.$node"; |
|
| 134 | - if(isset($this->loggers[$parentNode]) and $parentNode != $name) { |
|
| 135 | - $logger->setParent($this->loggers[$parentNode]); |
|
| 136 | - } |
|
| 137 | - $firstNode .= ".$node"; |
|
| 138 | - } |
|
| 139 | - } |
|
| 129 | + // if there are more nodes than one |
|
| 130 | + if(count($nodes) > 0) { |
|
| 131 | + // find parent node |
|
| 132 | + foreach($nodes as $node) { |
|
| 133 | + $parentNode = "$firstNode.$node"; |
|
| 134 | + if(isset($this->loggers[$parentNode]) and $parentNode != $name) { |
|
| 135 | + $logger->setParent($this->loggers[$parentNode]); |
|
| 136 | + } |
|
| 137 | + $firstNode .= ".$node"; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - $this->loggers[$name] = $logger; |
|
| 142 | - } |
|
| 141 | + $this->loggers[$name] = $logger; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - return $this->loggers[$name]; |
|
| 145 | - } |
|
| 144 | + return $this->loggers[$name]; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - /** |
|
| 148 | - * Returns the logger renderer map. |
|
| 149 | - * @return Payone_Log4php_LoggerRendererMap |
|
| 150 | - */ |
|
| 151 | - public function getRendererMap() { |
|
| 152 | - return $this->rendererMap; |
|
| 153 | - } |
|
| 147 | + /** |
|
| 148 | + * Returns the logger renderer map. |
|
| 149 | + * @return Payone_Log4php_LoggerRendererMap |
|
| 150 | + */ |
|
| 151 | + public function getRendererMap() { |
|
| 152 | + return $this->rendererMap; |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - /** |
|
| 156 | - * Returns the root logger. |
|
| 157 | - * @return Payone_Log4php_LoggerRoot |
|
| 158 | - */ |
|
| 159 | - public function getRootLogger() { |
|
| 160 | - if(!isset($this->root) or $this->root == null) { |
|
| 161 | - $this->root = new Payone_Log4php_LoggerRoot(); |
|
| 162 | - } |
|
| 163 | - return $this->root; |
|
| 164 | - } |
|
| 155 | + /** |
|
| 156 | + * Returns the root logger. |
|
| 157 | + * @return Payone_Log4php_LoggerRoot |
|
| 158 | + */ |
|
| 159 | + public function getRootLogger() { |
|
| 160 | + if(!isset($this->root) or $this->root == null) { |
|
| 161 | + $this->root = new Payone_Log4php_LoggerRoot(); |
|
| 162 | + } |
|
| 163 | + return $this->root; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Returns the main threshold level. |
|
| 168 | - * @return Payone_Log4php_LoggerLevel |
|
| 169 | - */ |
|
| 170 | - public function getThreshold() { |
|
| 171 | - return $this->threshold; |
|
| 172 | - } |
|
| 166 | + /** |
|
| 167 | + * Returns the main threshold level. |
|
| 168 | + * @return Payone_Log4php_LoggerLevel |
|
| 169 | + */ |
|
| 170 | + public function getThreshold() { |
|
| 171 | + return $this->threshold; |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - /** |
|
| 175 | - * Returns true if the hierarchy is disabled for given log level and false |
|
| 176 | - * otherwise. |
|
| 177 | - * @return boolean |
|
| 178 | - */ |
|
| 179 | - public function isDisabled(Payone_Log4php_LoggerLevel $level) { |
|
| 180 | - return ($this->threshold->toInt() > $level->toInt()); |
|
| 181 | - } |
|
| 174 | + /** |
|
| 175 | + * Returns true if the hierarchy is disabled for given log level and false |
|
| 176 | + * otherwise. |
|
| 177 | + * @return boolean |
|
| 178 | + */ |
|
| 179 | + public function isDisabled(Payone_Log4php_LoggerLevel $level) { |
|
| 180 | + return ($this->threshold->toInt() > $level->toInt()); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Reset all values contained in this hierarchy instance to their |
|
| 185 | - * default. |
|
| 186 | - * |
|
| 187 | - * This removes all appenders from all loggers, sets |
|
| 188 | - * the level of all non-root loggers to <i>null</i>, |
|
| 189 | - * sets their additivity flag to <i>true</i> and sets the level |
|
| 190 | - * of the root logger to {@link LOGGER_LEVEL_DEBUG}. |
|
| 191 | - * |
|
| 192 | - * <p>Existing loggers are not removed. They are just reset. |
|
| 193 | - * |
|
| 194 | - * <p>This method should be used sparingly and with care as it will |
|
| 195 | - * block all logging until it is completed.</p> |
|
| 196 | - */ |
|
| 197 | - public function resetConfiguration() { |
|
| 198 | - $root = $this->getRootLogger(); |
|
| 183 | + /** |
|
| 184 | + * Reset all values contained in this hierarchy instance to their |
|
| 185 | + * default. |
|
| 186 | + * |
|
| 187 | + * This removes all appenders from all loggers, sets |
|
| 188 | + * the level of all non-root loggers to <i>null</i>, |
|
| 189 | + * sets their additivity flag to <i>true</i> and sets the level |
|
| 190 | + * of the root logger to {@link LOGGER_LEVEL_DEBUG}. |
|
| 191 | + * |
|
| 192 | + * <p>Existing loggers are not removed. They are just reset. |
|
| 193 | + * |
|
| 194 | + * <p>This method should be used sparingly and with care as it will |
|
| 195 | + * block all logging until it is completed.</p> |
|
| 196 | + */ |
|
| 197 | + public function resetConfiguration() { |
|
| 198 | + $root = $this->getRootLogger(); |
|
| 199 | 199 | |
| 200 | - $root->setLevel(Payone_Log4php_LoggerLevel::getLevelDebug()); |
|
| 201 | - $this->setThreshold(Payone_Log4php_LoggerLevel::getLevelAll()); |
|
| 202 | - $this->shutDown(); |
|
| 200 | + $root->setLevel(Payone_Log4php_LoggerLevel::getLevelDebug()); |
|
| 201 | + $this->setThreshold(Payone_Log4php_LoggerLevel::getLevelAll()); |
|
| 202 | + $this->shutDown(); |
|
| 203 | 203 | |
| 204 | - foreach($this->loggers as $logger) { |
|
| 205 | - $logger->setLevel(null); |
|
| 206 | - $logger->setAdditivity(true); |
|
| 207 | - $logger->removeAllAppenders(); |
|
| 208 | - } |
|
| 204 | + foreach($this->loggers as $logger) { |
|
| 205 | + $logger->setLevel(null); |
|
| 206 | + $logger->setAdditivity(true); |
|
| 207 | + $logger->removeAllAppenders(); |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - $this->rendererMap->clear(); |
|
| 211 | - Payone_Log4php_LoggerAppenderPool::clear(); |
|
| 212 | - } |
|
| 210 | + $this->rendererMap->clear(); |
|
| 211 | + Payone_Log4php_LoggerAppenderPool::clear(); |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Sets the main threshold level. |
|
| 216 | - * @param Payone_Log4php_LoggerLevel $l |
|
| 217 | - */ |
|
| 218 | - public function setThreshold(Payone_Log4php_LoggerLevel $threshold) { |
|
| 219 | - $this->threshold = $threshold; |
|
| 220 | - } |
|
| 214 | + /** |
|
| 215 | + * Sets the main threshold level. |
|
| 216 | + * @param Payone_Log4php_LoggerLevel $l |
|
| 217 | + */ |
|
| 218 | + public function setThreshold(Payone_Log4php_LoggerLevel $threshold) { |
|
| 219 | + $this->threshold = $threshold; |
|
| 220 | + } |
|
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * Shutting down a hierarchy will <i>safely</i> close and remove |
|
| 224 | - * all appenders in all loggers including the root logger. |
|
| 225 | - * |
|
| 226 | - * The shutdown method is careful to close nested |
|
| 227 | - * appenders before closing regular appenders. This is allows |
|
| 228 | - * configurations where a regular appender is attached to a logger |
|
| 229 | - * and again to a nested appender. |
|
| 230 | - * |
|
| 231 | - * @todo Check if the last paragraph is correct. |
|
| 232 | - */ |
|
| 233 | - public function shutdown() { |
|
| 234 | - $this->root->removeAllAppenders(); |
|
| 222 | + /** |
|
| 223 | + * Shutting down a hierarchy will <i>safely</i> close and remove |
|
| 224 | + * all appenders in all loggers including the root logger. |
|
| 225 | + * |
|
| 226 | + * The shutdown method is careful to close nested |
|
| 227 | + * appenders before closing regular appenders. This is allows |
|
| 228 | + * configurations where a regular appender is attached to a logger |
|
| 229 | + * and again to a nested appender. |
|
| 230 | + * |
|
| 231 | + * @todo Check if the last paragraph is correct. |
|
| 232 | + */ |
|
| 233 | + public function shutdown() { |
|
| 234 | + $this->root->removeAllAppenders(); |
|
| 235 | 235 | |
| 236 | - foreach($this->loggers as $logger) { |
|
| 237 | - $logger->removeAllAppenders(); |
|
| 238 | - } |
|
| 239 | - } |
|
| 236 | + foreach($this->loggers as $logger) { |
|
| 237 | + $logger->removeAllAppenders(); |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | 240 | } |
@@ -41,16 +41,16 @@ |
||
| 41 | 41 | */ |
| 42 | 42 | class Payone_Log4php_LoggerAppenderPhp extends Payone_Log4php_LoggerAppender { |
| 43 | 43 | |
| 44 | - public function append(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 45 | - if($this->layout !== null) { |
|
| 46 | - $level = $event->getLevel(); |
|
| 47 | - if($level->isGreaterOrEqual(Payone_Log4php_LoggerLevel::getLevelError())) { |
|
| 48 | - trigger_error($this->layout->format($event), E_USER_ERROR); |
|
| 49 | - } else if ($level->isGreaterOrEqual(Payone_Log4php_LoggerLevel::getLevelWarn())) { |
|
| 50 | - trigger_error($this->layout->format($event), E_USER_WARNING); |
|
| 51 | - } else { |
|
| 52 | - trigger_error($this->layout->format($event), E_USER_NOTICE); |
|
| 53 | - } |
|
| 54 | - } |
|
| 55 | - } |
|
| 44 | + public function append(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 45 | + if($this->layout !== null) { |
|
| 46 | + $level = $event->getLevel(); |
|
| 47 | + if($level->isGreaterOrEqual(Payone_Log4php_LoggerLevel::getLevelError())) { |
|
| 48 | + trigger_error($this->layout->format($event), E_USER_ERROR); |
|
| 49 | + } else if ($level->isGreaterOrEqual(Payone_Log4php_LoggerLevel::getLevelWarn())) { |
|
| 50 | + trigger_error($this->layout->format($event), E_USER_WARNING); |
|
| 51 | + } else { |
|
| 52 | + trigger_error($this->layout->format($event), E_USER_NOTICE); |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -39,13 +39,13 @@ |
||
| 39 | 39 | */ |
| 40 | 40 | class Payone_Log4php_LoggerRendererDefault implements Payone_Log4php_LoggerRendererObject { |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Render objects by type casting |
|
| 44 | - * |
|
| 45 | - * @param mixed $o the object to render |
|
| 46 | - * @return string |
|
| 47 | - */ |
|
| 48 | - public function render($o) { |
|
| 49 | - return var_export($o, true); |
|
| 50 | - } |
|
| 42 | + /** |
|
| 43 | + * Render objects by type casting |
|
| 44 | + * |
|
| 45 | + * @param mixed $o the object to render |
|
| 46 | + * @return string |
|
| 47 | + */ |
|
| 48 | + public function render($o) { |
|
| 49 | + return var_export($o, true); |
|
| 50 | + } |
|
| 51 | 51 | } |
@@ -35,21 +35,21 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | abstract class Payone_Log4php_LoggerPatternConverterSuperglobal extends Payone_Log4php_LoggerPatternConverter { |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Name of the superglobal variable, to be defined by subclasses. |
|
| 40 | - * For example: "_SERVER" or "_ENV". |
|
| 41 | - */ |
|
| 42 | - protected $name; |
|
| 38 | + /** |
|
| 39 | + * Name of the superglobal variable, to be defined by subclasses. |
|
| 40 | + * For example: "_SERVER" or "_ENV". |
|
| 41 | + */ |
|
| 42 | + protected $name; |
|
| 43 | 43 | |
| 44 | - protected $value = ''; |
|
| 44 | + protected $value = ''; |
|
| 45 | 45 | |
| 46 | - public function activateOptions() { |
|
| 47 | - // Read the key from options array |
|
| 48 | - if (isset($this->option) && $this->option !== '') { |
|
| 49 | - $key = $this->option; |
|
| 50 | - } |
|
| 46 | + public function activateOptions() { |
|
| 47 | + // Read the key from options array |
|
| 48 | + if (isset($this->option) && $this->option !== '') { |
|
| 49 | + $key = $this->option; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /* |
|
| 52 | + /* |
|
| 53 | 53 | * There is a bug in PHP which doesn't allow superglobals to be |
| 54 | 54 | * accessed when their name is stored in a variable, e.g.: |
| 55 | 55 | * |
@@ -65,35 +65,35 @@ discard block |
||
| 65 | 65 | * |
| 66 | 66 | * That's why global is used here. |
| 67 | 67 | */ |
| 68 | - global ${$this->name}; |
|
| 68 | + global ${$this->name}; |
|
| 69 | 69 | |
| 70 | - // Check the given superglobal exists. It is possible that it is not initialized. |
|
| 71 | - if (!isset(${$this->name})) { |
|
| 72 | - $class = get_class($this); |
|
| 73 | - trigger_error("log4php: $class: Cannot find superglobal variable \${$this->name}.", E_USER_WARNING); |
|
| 74 | - return; |
|
| 75 | - } |
|
| 70 | + // Check the given superglobal exists. It is possible that it is not initialized. |
|
| 71 | + if (!isset(${$this->name})) { |
|
| 72 | + $class = get_class($this); |
|
| 73 | + trigger_error("log4php: $class: Cannot find superglobal variable \${$this->name}.", E_USER_WARNING); |
|
| 74 | + return; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - $source = ${$this->name}; |
|
| 77 | + $source = ${$this->name}; |
|
| 78 | 78 | |
| 79 | - // When the key is set, display the matching value |
|
| 80 | - if (isset($key)) { |
|
| 81 | - if (isset($source[$key])) { |
|
| 82 | - $this->value = $source[$key]; |
|
| 83 | - } |
|
| 84 | - } |
|
| 79 | + // When the key is set, display the matching value |
|
| 80 | + if (isset($key)) { |
|
| 81 | + if (isset($source[$key])) { |
|
| 82 | + $this->value = $source[$key]; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - // When the key is not set, display all values |
|
| 87 | - else { |
|
| 88 | - $values = array(); |
|
| 89 | - foreach($source as $key => $value) { |
|
| 90 | - $values[] = "$key=$value"; |
|
| 91 | - } |
|
| 92 | - $this->value = implode(', ', $values); |
|
| 93 | - } |
|
| 94 | - } |
|
| 86 | + // When the key is not set, display all values |
|
| 87 | + else { |
|
| 88 | + $values = array(); |
|
| 89 | + foreach($source as $key => $value) { |
|
| 90 | + $values[] = "$key=$value"; |
|
| 91 | + } |
|
| 92 | + $this->value = implode(', ', $values); |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 97 | - return $this->value; |
|
| 98 | - } |
|
| 96 | + public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 97 | + return $this->value; |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -47,168 +47,168 @@ |
||
| 47 | 47 | * @subpackage layouts |
| 48 | 48 | */ |
| 49 | 49 | class Payone_Log4php_LoggerLayoutHtml extends Payone_Log4php_LoggerLayout { |
| 50 | - /** |
|
| 51 | - * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 52 | - * default, it is set to false which means there will be no location |
|
| 53 | - * information output by this layout. If the the option is set to |
|
| 54 | - * true, then the file name and line number of the statement |
|
| 55 | - * at the origin of the log statement will be output. |
|
| 56 | - * |
|
| 57 | - * <p>If you are embedding this layout within a {@link Payone_Log4php_LoggerAppenderMail} |
|
| 58 | - * or a {@link Payone_Log4php_LoggerAppenderMailEvent} then make sure to set the |
|
| 59 | - * <b>LocationInfo</b> option of that appender as well. |
|
| 60 | - * @var boolean |
|
| 61 | - */ |
|
| 62 | - protected $locationInfo = false; |
|
| 50 | + /** |
|
| 51 | + * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 52 | + * default, it is set to false which means there will be no location |
|
| 53 | + * information output by this layout. If the the option is set to |
|
| 54 | + * true, then the file name and line number of the statement |
|
| 55 | + * at the origin of the log statement will be output. |
|
| 56 | + * |
|
| 57 | + * <p>If you are embedding this layout within a {@link Payone_Log4php_LoggerAppenderMail} |
|
| 58 | + * or a {@link Payone_Log4php_LoggerAppenderMailEvent} then make sure to set the |
|
| 59 | + * <b>LocationInfo</b> option of that appender as well. |
|
| 60 | + * @var boolean |
|
| 61 | + */ |
|
| 62 | + protected $locationInfo = false; |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * The <b>Title</b> option takes a String value. This option sets the |
|
| 66 | - * document title of the generated HTML document. |
|
| 67 | - * Defaults to 'Log4php Log Messages'. |
|
| 68 | - * @var string |
|
| 69 | - */ |
|
| 70 | - protected $title = "Log4php Log Messages"; |
|
| 64 | + /** |
|
| 65 | + * The <b>Title</b> option takes a String value. This option sets the |
|
| 66 | + * document title of the generated HTML document. |
|
| 67 | + * Defaults to 'Log4php Log Messages'. |
|
| 68 | + * @var string |
|
| 69 | + */ |
|
| 70 | + protected $title = "Log4php Log Messages"; |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 74 | - * default, it is set to false which means there will be no location |
|
| 75 | - * information output by this layout. If the the option is set to |
|
| 76 | - * true, then the file name and line number of the statement |
|
| 77 | - * at the origin of the log statement will be output. |
|
| 78 | - * |
|
| 79 | - * <p>If you are embedding this layout within a {@link Payone_Log4php_LoggerAppenderMail} |
|
| 80 | - * or a {@link Payone_Log4php_LoggerAppenderMailEvent} then make sure to set the |
|
| 81 | - * <b>LocationInfo</b> option of that appender as well. |
|
| 82 | - */ |
|
| 83 | - public function setLocationInfo($flag) { |
|
| 84 | - $this->setBoolean('locationInfo', $flag); |
|
| 85 | - } |
|
| 72 | + /** |
|
| 73 | + * The <b>LocationInfo</b> option takes a boolean value. By |
|
| 74 | + * default, it is set to false which means there will be no location |
|
| 75 | + * information output by this layout. If the the option is set to |
|
| 76 | + * true, then the file name and line number of the statement |
|
| 77 | + * at the origin of the log statement will be output. |
|
| 78 | + * |
|
| 79 | + * <p>If you are embedding this layout within a {@link Payone_Log4php_LoggerAppenderMail} |
|
| 80 | + * or a {@link Payone_Log4php_LoggerAppenderMailEvent} then make sure to set the |
|
| 81 | + * <b>LocationInfo</b> option of that appender as well. |
|
| 82 | + */ |
|
| 83 | + public function setLocationInfo($flag) { |
|
| 84 | + $this->setBoolean('locationInfo', $flag); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Returns the current value of the <b>LocationInfo</b> option. |
|
| 89 | - */ |
|
| 90 | - public function getLocationInfo() { |
|
| 91 | - return $this->locationInfo; |
|
| 92 | - } |
|
| 87 | + /** |
|
| 88 | + * Returns the current value of the <b>LocationInfo</b> option. |
|
| 89 | + */ |
|
| 90 | + public function getLocationInfo() { |
|
| 91 | + return $this->locationInfo; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * The <b>Title</b> option takes a String value. This option sets the |
|
| 96 | - * document title of the generated HTML document. |
|
| 97 | - * Defaults to 'Log4php Log Messages'. |
|
| 98 | - */ |
|
| 99 | - public function setTitle($title) { |
|
| 100 | - $this->setString('title', $title); |
|
| 101 | - } |
|
| 94 | + /** |
|
| 95 | + * The <b>Title</b> option takes a String value. This option sets the |
|
| 96 | + * document title of the generated HTML document. |
|
| 97 | + * Defaults to 'Log4php Log Messages'. |
|
| 98 | + */ |
|
| 99 | + public function setTitle($title) { |
|
| 100 | + $this->setString('title', $title); |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * @return string Returns the current value of the <b>Title</b> option. |
|
| 105 | - */ |
|
| 106 | - public function getTitle() { |
|
| 107 | - return $this->title; |
|
| 108 | - } |
|
| 103 | + /** |
|
| 104 | + * @return string Returns the current value of the <b>Title</b> option. |
|
| 105 | + */ |
|
| 106 | + public function getTitle() { |
|
| 107 | + return $this->title; |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * @return string Returns the content type output by this layout, i.e "text/html". |
|
| 112 | - */ |
|
| 113 | - public function getContentType() { |
|
| 114 | - return "text/html"; |
|
| 115 | - } |
|
| 110 | + /** |
|
| 111 | + * @return string Returns the content type output by this layout, i.e "text/html". |
|
| 112 | + */ |
|
| 113 | + public function getContentType() { |
|
| 114 | + return "text/html"; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 119 | - * @return string |
|
| 120 | - */ |
|
| 121 | - public function format(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 122 | - $sbuf = PHP_EOL . "<tr>" . PHP_EOL; |
|
| 117 | + /** |
|
| 118 | + * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 119 | + * @return string |
|
| 120 | + */ |
|
| 121 | + public function format(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 122 | + $sbuf = PHP_EOL . "<tr>" . PHP_EOL; |
|
| 123 | 123 | |
| 124 | - $sbuf .= "<td>"; |
|
| 125 | - $sbuf .= $event->getTime(); |
|
| 126 | - $sbuf .= "</td>" . PHP_EOL; |
|
| 124 | + $sbuf .= "<td>"; |
|
| 125 | + $sbuf .= $event->getTime(); |
|
| 126 | + $sbuf .= "</td>" . PHP_EOL; |
|
| 127 | 127 | |
| 128 | - $sbuf .= "<td title=\"" . $event->getThreadName() . " thread\">"; |
|
| 129 | - $sbuf .= $event->getThreadName(); |
|
| 130 | - $sbuf .= "</td>" . PHP_EOL; |
|
| 128 | + $sbuf .= "<td title=\"" . $event->getThreadName() . " thread\">"; |
|
| 129 | + $sbuf .= $event->getThreadName(); |
|
| 130 | + $sbuf .= "</td>" . PHP_EOL; |
|
| 131 | 131 | |
| 132 | - $sbuf .= "<td title=\"Level\">"; |
|
| 132 | + $sbuf .= "<td title=\"Level\">"; |
|
| 133 | 133 | |
| 134 | - $level = $event->getLevel(); |
|
| 134 | + $level = $event->getLevel(); |
|
| 135 | 135 | |
| 136 | - if ($level->equals(Payone_Log4php_LoggerLevel::getLevelDebug())) { |
|
| 137 | - $sbuf .= "<font color=\"#339933\">$level</font>"; |
|
| 138 | - } else if ($level->equals(Payone_Log4php_LoggerLevel::getLevelWarn())) { |
|
| 139 | - $sbuf .= "<font color=\"#993300\"><strong>$level</strong></font>"; |
|
| 140 | - } else { |
|
| 141 | - $sbuf .= $level; |
|
| 142 | - } |
|
| 143 | - $sbuf .= "</td>" . PHP_EOL; |
|
| 136 | + if ($level->equals(Payone_Log4php_LoggerLevel::getLevelDebug())) { |
|
| 137 | + $sbuf .= "<font color=\"#339933\">$level</font>"; |
|
| 138 | + } else if ($level->equals(Payone_Log4php_LoggerLevel::getLevelWarn())) { |
|
| 139 | + $sbuf .= "<font color=\"#993300\"><strong>$level</strong></font>"; |
|
| 140 | + } else { |
|
| 141 | + $sbuf .= $level; |
|
| 142 | + } |
|
| 143 | + $sbuf .= "</td>" . PHP_EOL; |
|
| 144 | 144 | |
| 145 | - $sbuf .= "<td title=\"" . htmlentities($event->getLoggerName(), ENT_QUOTES) . " category\">"; |
|
| 146 | - $sbuf .= htmlentities($event->getLoggerName(), ENT_QUOTES); |
|
| 147 | - $sbuf .= "</td>" . PHP_EOL; |
|
| 145 | + $sbuf .= "<td title=\"" . htmlentities($event->getLoggerName(), ENT_QUOTES) . " category\">"; |
|
| 146 | + $sbuf .= htmlentities($event->getLoggerName(), ENT_QUOTES); |
|
| 147 | + $sbuf .= "</td>" . PHP_EOL; |
|
| 148 | 148 | |
| 149 | - if ($this->locationInfo) { |
|
| 150 | - $locInfo = $event->getLocationInformation(); |
|
| 151 | - $sbuf .= "<td>"; |
|
| 152 | - $sbuf .= htmlentities($locInfo->getFileName(), ENT_QUOTES). ':' . $locInfo->getLineNumber(); |
|
| 153 | - $sbuf .= "</td>" . PHP_EOL; |
|
| 154 | - } |
|
| 149 | + if ($this->locationInfo) { |
|
| 150 | + $locInfo = $event->getLocationInformation(); |
|
| 151 | + $sbuf .= "<td>"; |
|
| 152 | + $sbuf .= htmlentities($locInfo->getFileName(), ENT_QUOTES). ':' . $locInfo->getLineNumber(); |
|
| 153 | + $sbuf .= "</td>" . PHP_EOL; |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - $sbuf .= "<td title=\"Message\">"; |
|
| 157 | - $sbuf .= htmlentities($event->getRenderedMessage(), ENT_QUOTES); |
|
| 158 | - $sbuf .= "</td>" . PHP_EOL; |
|
| 156 | + $sbuf .= "<td title=\"Message\">"; |
|
| 157 | + $sbuf .= htmlentities($event->getRenderedMessage(), ENT_QUOTES); |
|
| 158 | + $sbuf .= "</td>" . PHP_EOL; |
|
| 159 | 159 | |
| 160 | - $sbuf .= "</tr>" . PHP_EOL; |
|
| 160 | + $sbuf .= "</tr>" . PHP_EOL; |
|
| 161 | 161 | |
| 162 | - if ($event->getNDC() != null) { |
|
| 163 | - $sbuf .= "<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">"; |
|
| 164 | - $sbuf .= "NDC: " . htmlentities($event->getNDC(), ENT_QUOTES); |
|
| 165 | - $sbuf .= "</td></tr>" . PHP_EOL; |
|
| 166 | - } |
|
| 167 | - return $sbuf; |
|
| 168 | - } |
|
| 162 | + if ($event->getNDC() != null) { |
|
| 163 | + $sbuf .= "<tr><td bgcolor=\"#EEEEEE\" style=\"font-size : xx-small;\" colspan=\"6\" title=\"Nested Diagnostic Context\">"; |
|
| 164 | + $sbuf .= "NDC: " . htmlentities($event->getNDC(), ENT_QUOTES); |
|
| 165 | + $sbuf .= "</td></tr>" . PHP_EOL; |
|
| 166 | + } |
|
| 167 | + return $sbuf; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - /** |
|
| 171 | - * @return string Returns appropriate HTML headers. |
|
| 172 | - */ |
|
| 173 | - public function getHeader() { |
|
| 174 | - $sbuf = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" . PHP_EOL; |
|
| 175 | - $sbuf .= "<html>" . PHP_EOL; |
|
| 176 | - $sbuf .= "<head>" . PHP_EOL; |
|
| 177 | - $sbuf .= "<title>" . $this->title . "</title>" . PHP_EOL; |
|
| 178 | - $sbuf .= "<style type=\"text/css\">" . PHP_EOL; |
|
| 179 | - $sbuf .= "<!--" . PHP_EOL; |
|
| 180 | - $sbuf .= "body, table {font-family: arial,sans-serif; font-size: x-small;}" . PHP_EOL; |
|
| 181 | - $sbuf .= "th {background: #336699; color: #FFFFFF; text-align: left;}" . PHP_EOL; |
|
| 182 | - $sbuf .= "-->" . PHP_EOL; |
|
| 183 | - $sbuf .= "</style>" . PHP_EOL; |
|
| 184 | - $sbuf .= "</head>" . PHP_EOL; |
|
| 185 | - $sbuf .= "<body bgcolor=\"#FFFFFF\" topmargin=\"6\" leftmargin=\"6\">" . PHP_EOL; |
|
| 186 | - $sbuf .= "<hr size=\"1\" noshade>" . PHP_EOL; |
|
| 187 | - $sbuf .= "Log session start time " . strftime('%c', time()) . "<br>" . PHP_EOL; |
|
| 188 | - $sbuf .= "<br>" . PHP_EOL; |
|
| 189 | - $sbuf .= "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" bordercolor=\"#224466\" width=\"100%\">" . PHP_EOL; |
|
| 190 | - $sbuf .= "<tr>" . PHP_EOL; |
|
| 191 | - $sbuf .= "<th>Time</th>" . PHP_EOL; |
|
| 192 | - $sbuf .= "<th>Thread</th>" . PHP_EOL; |
|
| 193 | - $sbuf .= "<th>Level</th>" . PHP_EOL; |
|
| 194 | - $sbuf .= "<th>Category</th>" . PHP_EOL; |
|
| 195 | - if ($this->locationInfo) { |
|
| 196 | - $sbuf .= "<th>File:Line</th>" . PHP_EOL; |
|
| 197 | - } |
|
| 198 | - $sbuf .= "<th>Message</th>" . PHP_EOL; |
|
| 199 | - $sbuf .= "</tr>" . PHP_EOL; |
|
| 170 | + /** |
|
| 171 | + * @return string Returns appropriate HTML headers. |
|
| 172 | + */ |
|
| 173 | + public function getHeader() { |
|
| 174 | + $sbuf = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">" . PHP_EOL; |
|
| 175 | + $sbuf .= "<html>" . PHP_EOL; |
|
| 176 | + $sbuf .= "<head>" . PHP_EOL; |
|
| 177 | + $sbuf .= "<title>" . $this->title . "</title>" . PHP_EOL; |
|
| 178 | + $sbuf .= "<style type=\"text/css\">" . PHP_EOL; |
|
| 179 | + $sbuf .= "<!--" . PHP_EOL; |
|
| 180 | + $sbuf .= "body, table {font-family: arial,sans-serif; font-size: x-small;}" . PHP_EOL; |
|
| 181 | + $sbuf .= "th {background: #336699; color: #FFFFFF; text-align: left;}" . PHP_EOL; |
|
| 182 | + $sbuf .= "-->" . PHP_EOL; |
|
| 183 | + $sbuf .= "</style>" . PHP_EOL; |
|
| 184 | + $sbuf .= "</head>" . PHP_EOL; |
|
| 185 | + $sbuf .= "<body bgcolor=\"#FFFFFF\" topmargin=\"6\" leftmargin=\"6\">" . PHP_EOL; |
|
| 186 | + $sbuf .= "<hr size=\"1\" noshade>" . PHP_EOL; |
|
| 187 | + $sbuf .= "Log session start time " . strftime('%c', time()) . "<br>" . PHP_EOL; |
|
| 188 | + $sbuf .= "<br>" . PHP_EOL; |
|
| 189 | + $sbuf .= "<table cellspacing=\"0\" cellpadding=\"4\" border=\"1\" bordercolor=\"#224466\" width=\"100%\">" . PHP_EOL; |
|
| 190 | + $sbuf .= "<tr>" . PHP_EOL; |
|
| 191 | + $sbuf .= "<th>Time</th>" . PHP_EOL; |
|
| 192 | + $sbuf .= "<th>Thread</th>" . PHP_EOL; |
|
| 193 | + $sbuf .= "<th>Level</th>" . PHP_EOL; |
|
| 194 | + $sbuf .= "<th>Category</th>" . PHP_EOL; |
|
| 195 | + if ($this->locationInfo) { |
|
| 196 | + $sbuf .= "<th>File:Line</th>" . PHP_EOL; |
|
| 197 | + } |
|
| 198 | + $sbuf .= "<th>Message</th>" . PHP_EOL; |
|
| 199 | + $sbuf .= "</tr>" . PHP_EOL; |
|
| 200 | 200 | |
| 201 | - return $sbuf; |
|
| 202 | - } |
|
| 201 | + return $sbuf; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - /** |
|
| 205 | - * @return string Returns the appropriate HTML footers. |
|
| 206 | - */ |
|
| 207 | - public function getFooter() { |
|
| 208 | - $sbuf = "</table>" . PHP_EOL; |
|
| 209 | - $sbuf .= "<br>" . PHP_EOL; |
|
| 210 | - $sbuf .= "</body></html>"; |
|
| 204 | + /** |
|
| 205 | + * @return string Returns the appropriate HTML footers. |
|
| 206 | + */ |
|
| 207 | + public function getFooter() { |
|
| 208 | + $sbuf = "</table>" . PHP_EOL; |
|
| 209 | + $sbuf .= "<br>" . PHP_EOL; |
|
| 210 | + $sbuf .= "</body></html>"; |
|
| 211 | 211 | |
| 212 | - return $sbuf; |
|
| 213 | - } |
|
| 212 | + return $sbuf; |
|
| 213 | + } |
|
| 214 | 214 | } |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class Payone_Log4php_LoggerPatternConverterNewLine extends Payone_Log4php_LoggerPatternConverter { |
| 28 | 28 | |
| 29 | - public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 30 | - return PHP_EOL; |
|
| 31 | - } |
|
| 29 | + public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 30 | + return PHP_EOL; |
|
| 31 | + } |
|
| 32 | 32 | } |
@@ -47,43 +47,43 @@ |
||
| 47 | 47 | */ |
| 48 | 48 | class Payone_Log4php_LoggerFilterStringMatch extends Payone_Log4php_LoggerFilter { |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @var boolean |
|
| 52 | - */ |
|
| 53 | - protected $acceptOnMatch = true; |
|
| 50 | + /** |
|
| 51 | + * @var boolean |
|
| 52 | + */ |
|
| 53 | + protected $acceptOnMatch = true; |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 58 | - protected $stringToMatch; |
|
| 55 | + /** |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | + protected $stringToMatch; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * @param mixed $acceptOnMatch a boolean or a string ('true' or 'false') |
|
| 62 | - */ |
|
| 63 | - public function setAcceptOnMatch($acceptOnMatch) { |
|
| 64 | - $this->setBoolean('acceptOnMatch', $acceptOnMatch); |
|
| 65 | - } |
|
| 60 | + /** |
|
| 61 | + * @param mixed $acceptOnMatch a boolean or a string ('true' or 'false') |
|
| 62 | + */ |
|
| 63 | + public function setAcceptOnMatch($acceptOnMatch) { |
|
| 64 | + $this->setBoolean('acceptOnMatch', $acceptOnMatch); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @param string $s the string to match |
|
| 69 | - */ |
|
| 70 | - public function setStringToMatch($string) { |
|
| 71 | - $this->setString('stringToMatch', $string); |
|
| 72 | - } |
|
| 67 | + /** |
|
| 68 | + * @param string $s the string to match |
|
| 69 | + */ |
|
| 70 | + public function setStringToMatch($string) { |
|
| 71 | + $this->setString('stringToMatch', $string); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * @return integer a {@link LOGGER_FILTER_NEUTRAL} is there is no string match. |
|
| 76 | - */ |
|
| 77 | - public function decide(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 78 | - $msg = $event->getRenderedMessage(); |
|
| 74 | + /** |
|
| 75 | + * @return integer a {@link LOGGER_FILTER_NEUTRAL} is there is no string match. |
|
| 76 | + */ |
|
| 77 | + public function decide(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 78 | + $msg = $event->getRenderedMessage(); |
|
| 79 | 79 | |
| 80 | - if($msg === null or $this->stringToMatch === null) { |
|
| 81 | - return Payone_Log4php_LoggerFilter::NEUTRAL; |
|
| 82 | - } |
|
| 80 | + if($msg === null or $this->stringToMatch === null) { |
|
| 81 | + return Payone_Log4php_LoggerFilter::NEUTRAL; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - if(strpos($msg, $this->stringToMatch) !== false ) { |
|
| 85 | - return ($this->acceptOnMatch) ? Payone_Log4php_LoggerFilter::ACCEPT : Payone_Log4php_LoggerFilter::DENY; |
|
| 86 | - } |
|
| 87 | - return Payone_Log4php_LoggerFilter::NEUTRAL; |
|
| 88 | - } |
|
| 84 | + if(strpos($msg, $this->stringToMatch) !== false ) { |
|
| 85 | + return ($this->acceptOnMatch) ? Payone_Log4php_LoggerFilter::ACCEPT : Payone_Log4php_LoggerFilter::DENY; |
|
| 86 | + } |
|
| 87 | + return Payone_Log4php_LoggerFilter::NEUTRAL; |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -23,131 +23,131 @@ |
||
| 23 | 23 | * @package log4php |
| 24 | 24 | */ |
| 25 | 25 | class Payone_Log4php_LoggerReflectionUtils { |
| 26 | - /** the target object */ |
|
| 27 | - private $obj; |
|
| 26 | + /** the target object */ |
|
| 27 | + private $obj; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Create a new LoggerReflectionUtils for the specified Object. |
|
| 31 | - * This is done in prepartion for invoking {@link setProperty()} |
|
| 32 | - * one or more times. |
|
| 33 | - * @param object &$obj the object for which to set properties |
|
| 34 | - */ |
|
| 35 | - public function __construct($obj) { |
|
| 36 | - $this->obj = $obj; |
|
| 37 | - } |
|
| 29 | + /** |
|
| 30 | + * Create a new LoggerReflectionUtils for the specified Object. |
|
| 31 | + * This is done in prepartion for invoking {@link setProperty()} |
|
| 32 | + * one or more times. |
|
| 33 | + * @param object &$obj the object for which to set properties |
|
| 34 | + */ |
|
| 35 | + public function __construct($obj) { |
|
| 36 | + $this->obj = $obj; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Set the properties of an object passed as a parameter in one |
|
| 41 | - * go. The <code>properties</code> are parsed relative to a |
|
| 42 | - * <code>prefix</code>. |
|
| 43 | - * |
|
| 44 | - * @param object $obj The object to configure. |
|
| 45 | - * @param array $properties An array containing keys and values. |
|
| 46 | - * @param string $prefix Only keys having the specified prefix will be set. |
|
| 47 | - */ |
|
| 48 | - // TODO: check, if this is really useful |
|
| 49 | - public static function setPropertiesByObject($obj, $properties, $prefix) { |
|
| 50 | - $pSetter = new Payone_Log4php_LoggerReflectionUtils($obj); |
|
| 51 | - return $pSetter->setProperties($properties, $prefix); |
|
| 52 | - } |
|
| 39 | + /** |
|
| 40 | + * Set the properties of an object passed as a parameter in one |
|
| 41 | + * go. The <code>properties</code> are parsed relative to a |
|
| 42 | + * <code>prefix</code>. |
|
| 43 | + * |
|
| 44 | + * @param object $obj The object to configure. |
|
| 45 | + * @param array $properties An array containing keys and values. |
|
| 46 | + * @param string $prefix Only keys having the specified prefix will be set. |
|
| 47 | + */ |
|
| 48 | + // TODO: check, if this is really useful |
|
| 49 | + public static function setPropertiesByObject($obj, $properties, $prefix) { |
|
| 50 | + $pSetter = new Payone_Log4php_LoggerReflectionUtils($obj); |
|
| 51 | + return $pSetter->setProperties($properties, $prefix); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Set the properites for the object that match the |
|
| 57 | - * <code>prefix</code> passed as parameter. |
|
| 58 | - * |
|
| 59 | - * Example: |
|
| 60 | - * |
|
| 61 | - * $arr['xxxname'] = 'Joe'; |
|
| 62 | - * $arr['xxxmale'] = true; |
|
| 63 | - * and prefix xxx causes setName and setMale. |
|
| 64 | - * |
|
| 65 | - * @param array $properties An array containing keys and values. |
|
| 66 | - * @param string $prefix Only keys having the specified prefix will be set. |
|
| 67 | - */ |
|
| 68 | - // TODO: check, if this is really useful |
|
| 69 | - public function setProperties($properties, $prefix) { |
|
| 70 | - $len = strlen($prefix); |
|
| 71 | - reset($properties); |
|
| 72 | - while(list($key,) = each($properties)) { |
|
| 73 | - if(strpos($key, $prefix) === 0) { |
|
| 74 | - if(strpos($key, '.', ($len + 1)) > 0) { |
|
| 75 | - continue; |
|
| 76 | - } |
|
| 77 | - $value = Payone_Log4php_LoggerOptionConverter::findAndSubst($key, $properties); |
|
| 78 | - $key = substr($key, $len); |
|
| 79 | - if($key == 'layout' and ($this->obj instanceof Payone_Log4php_LoggerAppender)) { |
|
| 80 | - continue; |
|
| 81 | - } |
|
| 82 | - $this->setProperty($key, $value); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - $this->activate(); |
|
| 86 | - } |
|
| 55 | + /** |
|
| 56 | + * Set the properites for the object that match the |
|
| 57 | + * <code>prefix</code> passed as parameter. |
|
| 58 | + * |
|
| 59 | + * Example: |
|
| 60 | + * |
|
| 61 | + * $arr['xxxname'] = 'Joe'; |
|
| 62 | + * $arr['xxxmale'] = true; |
|
| 63 | + * and prefix xxx causes setName and setMale. |
|
| 64 | + * |
|
| 65 | + * @param array $properties An array containing keys and values. |
|
| 66 | + * @param string $prefix Only keys having the specified prefix will be set. |
|
| 67 | + */ |
|
| 68 | + // TODO: check, if this is really useful |
|
| 69 | + public function setProperties($properties, $prefix) { |
|
| 70 | + $len = strlen($prefix); |
|
| 71 | + reset($properties); |
|
| 72 | + while(list($key,) = each($properties)) { |
|
| 73 | + if(strpos($key, $prefix) === 0) { |
|
| 74 | + if(strpos($key, '.', ($len + 1)) > 0) { |
|
| 75 | + continue; |
|
| 76 | + } |
|
| 77 | + $value = Payone_Log4php_LoggerOptionConverter::findAndSubst($key, $properties); |
|
| 78 | + $key = substr($key, $len); |
|
| 79 | + if($key == 'layout' and ($this->obj instanceof Payone_Log4php_LoggerAppender)) { |
|
| 80 | + continue; |
|
| 81 | + } |
|
| 82 | + $this->setProperty($key, $value); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + $this->activate(); |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Set a property on this PropertySetter's Object. If successful, this |
|
| 90 | - * method will invoke a setter method on the underlying Object. The |
|
| 91 | - * setter is the one for the specified property name and the value is |
|
| 92 | - * determined partly from the setter argument type and partly from the |
|
| 93 | - * value specified in the call to this method. |
|
| 94 | - * |
|
| 95 | - * <p>If the setter expects a String no conversion is necessary. |
|
| 96 | - * If it expects an int, then an attempt is made to convert 'value' |
|
| 97 | - * to an int using new Integer(value). If the setter expects a boolean, |
|
| 98 | - * the conversion is by new Boolean(value). |
|
| 99 | - * |
|
| 100 | - * @param string $name name of the property |
|
| 101 | - * @param string $value String value of the property |
|
| 102 | - */ |
|
| 103 | - public function setProperty($name, $value) { |
|
| 104 | - if($value === null) { |
|
| 105 | - return; |
|
| 106 | - } |
|
| 88 | + /** |
|
| 89 | + * Set a property on this PropertySetter's Object. If successful, this |
|
| 90 | + * method will invoke a setter method on the underlying Object. The |
|
| 91 | + * setter is the one for the specified property name and the value is |
|
| 92 | + * determined partly from the setter argument type and partly from the |
|
| 93 | + * value specified in the call to this method. |
|
| 94 | + * |
|
| 95 | + * <p>If the setter expects a String no conversion is necessary. |
|
| 96 | + * If it expects an int, then an attempt is made to convert 'value' |
|
| 97 | + * to an int using new Integer(value). If the setter expects a boolean, |
|
| 98 | + * the conversion is by new Boolean(value). |
|
| 99 | + * |
|
| 100 | + * @param string $name name of the property |
|
| 101 | + * @param string $value String value of the property |
|
| 102 | + */ |
|
| 103 | + public function setProperty($name, $value) { |
|
| 104 | + if($value === null) { |
|
| 105 | + return; |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - $method = "set" . ucfirst($name); |
|
| 108 | + $method = "set" . ucfirst($name); |
|
| 109 | 109 | |
| 110 | - if(!method_exists($this->obj, $method)) { |
|
| 111 | - throw new Exception("Error setting log4php property $name to $value: no method $method in class ".get_class($this->obj)."!"); |
|
| 112 | - } else { |
|
| 113 | - return call_user_func(array($this->obj, $method), $value); |
|
| 114 | - } |
|
| 115 | - } |
|
| 110 | + if(!method_exists($this->obj, $method)) { |
|
| 111 | + throw new Exception("Error setting log4php property $name to $value: no method $method in class ".get_class($this->obj)."!"); |
|
| 112 | + } else { |
|
| 113 | + return call_user_func(array($this->obj, $method), $value); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - public function activate() { |
|
| 118 | - if(method_exists($this->obj, 'activateoptions')) { |
|
| 119 | - return call_user_func(array($this->obj, 'activateoptions')); |
|
| 120 | - } |
|
| 121 | - } |
|
| 117 | + public function activate() { |
|
| 118 | + if(method_exists($this->obj, 'activateoptions')) { |
|
| 119 | + return call_user_func(array($this->obj, 'activateoptions')); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | 122 | |
| 123 | - /** |
|
| 124 | - * Creates an instances from the given class name. |
|
| 125 | - * |
|
| 126 | - * @param string $classname |
|
| 127 | - * @return an object from the class with the given classname |
|
| 128 | - */ |
|
| 129 | - public static function createObject($class) { |
|
| 130 | - if(!empty($class)) { |
|
| 131 | - return new $class(); |
|
| 132 | - } |
|
| 133 | - return null; |
|
| 134 | - } |
|
| 123 | + /** |
|
| 124 | + * Creates an instances from the given class name. |
|
| 125 | + * |
|
| 126 | + * @param string $classname |
|
| 127 | + * @return an object from the class with the given classname |
|
| 128 | + */ |
|
| 129 | + public static function createObject($class) { |
|
| 130 | + if(!empty($class)) { |
|
| 131 | + return new $class(); |
|
| 132 | + } |
|
| 133 | + return null; |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - /** |
|
| 137 | - * @param object $object |
|
| 138 | - * @param string $name |
|
| 139 | - * @param mixed $value |
|
| 140 | - */ |
|
| 141 | - public static function setter($object, $name, $value) { |
|
| 142 | - if (empty($name)) { |
|
| 143 | - return false; |
|
| 144 | - } |
|
| 145 | - $methodName = 'set'.ucfirst($name); |
|
| 146 | - if (method_exists($object, $methodName)) { |
|
| 147 | - return call_user_func(array($object, $methodName), $value); |
|
| 148 | - } else { |
|
| 149 | - return false; |
|
| 150 | - } |
|
| 151 | - } |
|
| 136 | + /** |
|
| 137 | + * @param object $object |
|
| 138 | + * @param string $name |
|
| 139 | + * @param mixed $value |
|
| 140 | + */ |
|
| 141 | + public static function setter($object, $name, $value) { |
|
| 142 | + if (empty($name)) { |
|
| 143 | + return false; |
|
| 144 | + } |
|
| 145 | + $methodName = 'set'.ucfirst($name); |
|
| 146 | + if (method_exists($object, $methodName)) { |
|
| 147 | + return call_user_func(array($object, $methodName), $value); |
|
| 148 | + } else { |
|
| 149 | + return false; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | 153 | } |