@@ -199,7 +199,7 @@ |
||
| 199 | 199 | * Parses the formatting modifiers and produces the corresponding |
| 200 | 200 | * LoggerFormattingInfo object. |
| 201 | 201 | * |
| 202 | - * @param string $modifier |
|
| 202 | + * @param string $modifiers |
|
| 203 | 203 | * @return Payone_Log4php_LoggerFormattingInfo |
| 204 | 204 | * @throws LoggerException |
| 205 | 205 | */ |
@@ -33,206 +33,206 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class Payone_Log4php_LoggerPatternParser { |
| 35 | 35 | |
| 36 | - /** Escape character for conversion words in the conversion pattern. */ |
|
| 37 | - const ESCAPE_CHAR = '%'; |
|
| 36 | + /** Escape character for conversion words in the conversion pattern. */ |
|
| 37 | + const ESCAPE_CHAR = '%'; |
|
| 38 | 38 | |
| 39 | - /** Maps conversion words to relevant converters. */ |
|
| 40 | - private $converterMap; |
|
| 39 | + /** Maps conversion words to relevant converters. */ |
|
| 40 | + private $converterMap; |
|
| 41 | 41 | |
| 42 | - /** Conversion pattern used in layout. */ |
|
| 43 | - private $pattern; |
|
| 42 | + /** Conversion pattern used in layout. */ |
|
| 43 | + private $pattern; |
|
| 44 | 44 | |
| 45 | - /** Regex pattern used for parsing the conversion pattern. */ |
|
| 46 | - private $regex; |
|
| 45 | + /** Regex pattern used for parsing the conversion pattern. */ |
|
| 46 | + private $regex; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * First converter in the chain. |
|
| 50 | - * @var Payone_Log4php_LoggerPatternConverter |
|
| 51 | - */ |
|
| 52 | - private $head; |
|
| 48 | + /** |
|
| 49 | + * First converter in the chain. |
|
| 50 | + * @var Payone_Log4php_LoggerPatternConverter |
|
| 51 | + */ |
|
| 52 | + private $head; |
|
| 53 | 53 | |
| 54 | - /** Last converter in the chain. */ |
|
| 55 | - private $tail; |
|
| 54 | + /** Last converter in the chain. */ |
|
| 55 | + private $tail; |
|
| 56 | 56 | |
| 57 | - public function __construct($pattern, $converterMap) { |
|
| 58 | - $this->pattern = $pattern; |
|
| 59 | - $this->converterMap = $converterMap; |
|
| 57 | + public function __construct($pattern, $converterMap) { |
|
| 58 | + $this->pattern = $pattern; |
|
| 59 | + $this->converterMap = $converterMap; |
|
| 60 | 60 | |
| 61 | - // Construct the regex pattern |
|
| 62 | - $this->regex = |
|
| 63 | - '/' . // Starting regex pattern delimiter |
|
| 64 | - self::ESCAPE_CHAR . // Character which marks the start of the conversion pattern |
|
| 65 | - '(?P<modifiers>[0-9.-]*)' . // Format modifiers (optional) |
|
| 66 | - '(?P<word>[a-zA-Z]+)' . // The conversion word |
|
| 67 | - '(?P<option>{[^}]*})?' . // Conversion option in braces (optional) |
|
| 68 | - '/'; // Ending regex pattern delimiter |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Parses the conversion pattern string, converts it to a chain of pattern |
|
| 73 | - * converters and returns the first converter in the chain. |
|
| 74 | - * |
|
| 75 | - * @return Payone_Log4php_LoggerPatternConverter |
|
| 76 | - */ |
|
| 77 | - public function parse() { |
|
| 61 | + // Construct the regex pattern |
|
| 62 | + $this->regex = |
|
| 63 | + '/' . // Starting regex pattern delimiter |
|
| 64 | + self::ESCAPE_CHAR . // Character which marks the start of the conversion pattern |
|
| 65 | + '(?P<modifiers>[0-9.-]*)' . // Format modifiers (optional) |
|
| 66 | + '(?P<word>[a-zA-Z]+)' . // The conversion word |
|
| 67 | + '(?P<option>{[^}]*})?' . // Conversion option in braces (optional) |
|
| 68 | + '/'; // Ending regex pattern delimiter |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Parses the conversion pattern string, converts it to a chain of pattern |
|
| 73 | + * converters and returns the first converter in the chain. |
|
| 74 | + * |
|
| 75 | + * @return Payone_Log4php_LoggerPatternConverter |
|
| 76 | + */ |
|
| 77 | + public function parse() { |
|
| 78 | 78 | |
| 79 | - // Skip parsing if the pattern is empty |
|
| 80 | - if (empty($this->pattern)) { |
|
| 81 | - $this->addLiteral(''); |
|
| 82 | - return $this->head; |
|
| 83 | - } |
|
| 79 | + // Skip parsing if the pattern is empty |
|
| 80 | + if (empty($this->pattern)) { |
|
| 81 | + $this->addLiteral(''); |
|
| 82 | + return $this->head; |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - // Find all conversion words in the conversion pattern |
|
| 86 | - $count = preg_match_all($this->regex, $this->pattern, $matches, PREG_OFFSET_CAPTURE); |
|
| 87 | - if ($count === false) { |
|
| 88 | - $error = error_get_last(); |
|
| 89 | - throw new Payone_Log4php_LoggerException("Failed parsing layotut pattern: {$error['message']}"); |
|
| 90 | - } |
|
| 85 | + // Find all conversion words in the conversion pattern |
|
| 86 | + $count = preg_match_all($this->regex, $this->pattern, $matches, PREG_OFFSET_CAPTURE); |
|
| 87 | + if ($count === false) { |
|
| 88 | + $error = error_get_last(); |
|
| 89 | + throw new Payone_Log4php_LoggerException("Failed parsing layotut pattern: {$error['message']}"); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - $prevEnd = 0; |
|
| 92 | + $prevEnd = 0; |
|
| 93 | 93 | |
| 94 | - foreach($matches[0] as $key => $item) { |
|
| 94 | + foreach($matches[0] as $key => $item) { |
|
| 95 | 95 | |
| 96 | - // Locate where the conversion command starts and ends |
|
| 97 | - $length = strlen($item[0]); |
|
| 98 | - $start = $item[1]; |
|
| 99 | - $end = $item[1] + $length; |
|
| 96 | + // Locate where the conversion command starts and ends |
|
| 97 | + $length = strlen($item[0]); |
|
| 98 | + $start = $item[1]; |
|
| 99 | + $end = $item[1] + $length; |
|
| 100 | 100 | |
| 101 | - // Find any literal expressions between matched commands |
|
| 102 | - if ($start > $prevEnd) { |
|
| 103 | - $literal = substr($this->pattern, $prevEnd, $start - $prevEnd); |
|
| 104 | - $this->addLiteral($literal); |
|
| 105 | - } |
|
| 101 | + // Find any literal expressions between matched commands |
|
| 102 | + if ($start > $prevEnd) { |
|
| 103 | + $literal = substr($this->pattern, $prevEnd, $start - $prevEnd); |
|
| 104 | + $this->addLiteral($literal); |
|
| 105 | + } |
|
| 106 | 106 | |
| 107 | - // Extract the data from the matched command |
|
| 108 | - $word = !empty($matches['word'][$key]) ? $matches['word'][$key][0] : null; |
|
| 109 | - $modifiers = !empty($matches['modifiers'][$key]) ? $matches['modifiers'][$key][0] : null; |
|
| 110 | - $option = !empty($matches['option'][$key]) ? $matches['option'][$key][0] : null; |
|
| 107 | + // Extract the data from the matched command |
|
| 108 | + $word = !empty($matches['word'][$key]) ? $matches['word'][$key][0] : null; |
|
| 109 | + $modifiers = !empty($matches['modifiers'][$key]) ? $matches['modifiers'][$key][0] : null; |
|
| 110 | + $option = !empty($matches['option'][$key]) ? $matches['option'][$key][0] : null; |
|
| 111 | 111 | |
| 112 | - // Create a converter and add it to the chain |
|
| 113 | - $this->addConverter($word, $modifiers, $option); |
|
| 112 | + // Create a converter and add it to the chain |
|
| 113 | + $this->addConverter($word, $modifiers, $option); |
|
| 114 | 114 | |
| 115 | - $prevEnd = $end; |
|
| 116 | - } |
|
| 115 | + $prevEnd = $end; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - // Add any trailing literals |
|
| 119 | - if ($end < strlen($this->pattern)) { |
|
| 120 | - $literal = substr($this->pattern, $end); |
|
| 121 | - $this->addLiteral($literal); |
|
| 122 | - } |
|
| 118 | + // Add any trailing literals |
|
| 119 | + if ($end < strlen($this->pattern)) { |
|
| 120 | + $literal = substr($this->pattern, $end); |
|
| 121 | + $this->addLiteral($literal); |
|
| 122 | + } |
|
| 123 | 123 | |
| 124 | - return $this->head; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Adds a literal converter to the converter chain. |
|
| 129 | - * @param string $string The string for the literal converter. |
|
| 130 | - */ |
|
| 131 | - private function addLiteral($string) { |
|
| 132 | - $converter = new Payone_Log4php_LoggerPatternConverterLiteral($string); |
|
| 133 | - $this->addToChain($converter); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Adds a non-literal converter to the converter chain. |
|
| 138 | - * |
|
| 139 | - * @param string $word The conversion word, used to determine which |
|
| 140 | - * converter will be used. |
|
| 141 | - * @param string $modifiers Formatting modifiers. |
|
| 142 | - * @param string $option Option to pass to the converter. |
|
| 143 | - */ |
|
| 144 | - private function addConverter($word, $modifiers, $option) { |
|
| 145 | - $formattingInfo = $this->parseModifiers($modifiers); |
|
| 146 | - $option = trim($option, "{} "); |
|
| 124 | + return $this->head; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Adds a literal converter to the converter chain. |
|
| 129 | + * @param string $string The string for the literal converter. |
|
| 130 | + */ |
|
| 131 | + private function addLiteral($string) { |
|
| 132 | + $converter = new Payone_Log4php_LoggerPatternConverterLiteral($string); |
|
| 133 | + $this->addToChain($converter); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Adds a non-literal converter to the converter chain. |
|
| 138 | + * |
|
| 139 | + * @param string $word The conversion word, used to determine which |
|
| 140 | + * converter will be used. |
|
| 141 | + * @param string $modifiers Formatting modifiers. |
|
| 142 | + * @param string $option Option to pass to the converter. |
|
| 143 | + */ |
|
| 144 | + private function addConverter($word, $modifiers, $option) { |
|
| 145 | + $formattingInfo = $this->parseModifiers($modifiers); |
|
| 146 | + $option = trim($option, "{} "); |
|
| 147 | 147 | |
| 148 | - if (isset($this->converterMap[$word])) { |
|
| 149 | - $converter = $this->getConverter($word, $formattingInfo, $option); |
|
| 150 | - $this->addToChain($converter); |
|
| 151 | - } else { |
|
| 152 | - trigger_error("log4php: Invalid keyword '%$word' in converison pattern. Ignoring keyword.", E_USER_WARNING); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Determines which converter to use based on the conversion word. Creates |
|
| 158 | - * an instance of the converter using the provided formatting info and |
|
| 159 | - * option and returns it. |
|
| 160 | - * |
|
| 161 | - * @param string $word The conversion word. |
|
| 162 | - * @param Payone_Log4php_LoggerFormattingInfo $info Formatting info. |
|
| 163 | - * @param string $option Converter option. |
|
| 164 | - * |
|
| 165 | - * @throws LoggerException |
|
| 166 | - * |
|
| 167 | - * @return Payone_Log4php_LoggerPatternConverter |
|
| 168 | - */ |
|
| 169 | - private function getConverter($word, $info, $option) { |
|
| 170 | - if (!isset($this->converterMap[$word])) { |
|
| 171 | - throw new Payone_Log4php_LoggerException("Invalid keyword '%$word' in converison pattern. Ignoring keyword."); |
|
| 172 | - } |
|
| 148 | + if (isset($this->converterMap[$word])) { |
|
| 149 | + $converter = $this->getConverter($word, $formattingInfo, $option); |
|
| 150 | + $this->addToChain($converter); |
|
| 151 | + } else { |
|
| 152 | + trigger_error("log4php: Invalid keyword '%$word' in converison pattern. Ignoring keyword.", E_USER_WARNING); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Determines which converter to use based on the conversion word. Creates |
|
| 158 | + * an instance of the converter using the provided formatting info and |
|
| 159 | + * option and returns it. |
|
| 160 | + * |
|
| 161 | + * @param string $word The conversion word. |
|
| 162 | + * @param Payone_Log4php_LoggerFormattingInfo $info Formatting info. |
|
| 163 | + * @param string $option Converter option. |
|
| 164 | + * |
|
| 165 | + * @throws LoggerException |
|
| 166 | + * |
|
| 167 | + * @return Payone_Log4php_LoggerPatternConverter |
|
| 168 | + */ |
|
| 169 | + private function getConverter($word, $info, $option) { |
|
| 170 | + if (!isset($this->converterMap[$word])) { |
|
| 171 | + throw new Payone_Log4php_LoggerException("Invalid keyword '%$word' in converison pattern. Ignoring keyword."); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - $converterClass = $this->converterMap[$word]; |
|
| 175 | - if(!class_exists($converterClass)) { |
|
| 176 | - throw new Payone_Log4php_LoggerException("Class '$converterClass' does not exist."); |
|
| 177 | - } |
|
| 174 | + $converterClass = $this->converterMap[$word]; |
|
| 175 | + if(!class_exists($converterClass)) { |
|
| 176 | + throw new Payone_Log4php_LoggerException("Class '$converterClass' does not exist."); |
|
| 177 | + } |
|
| 178 | 178 | |
| 179 | - $converter = new $converterClass($info, $option); |
|
| 180 | - if(!($converter instanceof Payone_Log4php_LoggerPatternConverter)) { |
|
| 181 | - throw new Payone_Log4php_LoggerException("Class '$converterClass' is not an instance of Payone_Log4php_LoggerPatternConverter."); |
|
| 182 | - } |
|
| 179 | + $converter = new $converterClass($info, $option); |
|
| 180 | + if(!($converter instanceof Payone_Log4php_LoggerPatternConverter)) { |
|
| 181 | + throw new Payone_Log4php_LoggerException("Class '$converterClass' is not an instance of Payone_Log4php_LoggerPatternConverter."); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - return $converter; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** Adds a converter to the chain and updates $head and $tail pointers. */ |
|
| 188 | - private function addToChain(LoggerPatternConverter $converter) { |
|
| 189 | - if (!isset($this->head)) { |
|
| 190 | - $this->head = $converter; |
|
| 191 | - $this->tail = $this->head; |
|
| 192 | - } else { |
|
| 193 | - $this->tail->next = $converter; |
|
| 194 | - $this->tail = $this->tail->next; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Parses the formatting modifiers and produces the corresponding |
|
| 200 | - * LoggerFormattingInfo object. |
|
| 201 | - * |
|
| 202 | - * @param string $modifier |
|
| 203 | - * @return Payone_Log4php_LoggerFormattingInfo |
|
| 204 | - * @throws LoggerException |
|
| 205 | - */ |
|
| 206 | - private function parseModifiers($modifiers) { |
|
| 207 | - $info = new Payone_Log4php_LoggerFormattingInfo(); |
|
| 208 | - |
|
| 209 | - // If no modifiers are given, return default values |
|
| 210 | - if (empty($modifiers)) { |
|
| 211 | - return $info; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // Validate |
|
| 215 | - $pattern = '/^(-?[0-9]+)?\.?-?[0-9]+$/'; |
|
| 216 | - if (!preg_match($pattern, $modifiers)) { |
|
| 217 | - trigger_error("log4php: Invalid modifier in conversion pattern: [$modifiers]. Ignoring modifier.", E_USER_WARNING); |
|
| 218 | - return $info; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - $parts = explode('.', $modifiers); |
|
| 222 | - |
|
| 223 | - if (!empty($parts[0])) { |
|
| 224 | - $minPart = (integer) $parts[0]; |
|
| 225 | - $info->min = abs($minPart); |
|
| 226 | - $info->padLeft = ($minPart > 0); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if (!empty($parts[1])) { |
|
| 230 | - $maxPart = (integer) $parts[1]; |
|
| 231 | - $info->max = abs($maxPart); |
|
| 232 | - $info->trimLeft = ($maxPart > 0); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return $info; |
|
| 236 | - } |
|
| 184 | + return $converter; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** Adds a converter to the chain and updates $head and $tail pointers. */ |
|
| 188 | + private function addToChain(LoggerPatternConverter $converter) { |
|
| 189 | + if (!isset($this->head)) { |
|
| 190 | + $this->head = $converter; |
|
| 191 | + $this->tail = $this->head; |
|
| 192 | + } else { |
|
| 193 | + $this->tail->next = $converter; |
|
| 194 | + $this->tail = $this->tail->next; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Parses the formatting modifiers and produces the corresponding |
|
| 200 | + * LoggerFormattingInfo object. |
|
| 201 | + * |
|
| 202 | + * @param string $modifier |
|
| 203 | + * @return Payone_Log4php_LoggerFormattingInfo |
|
| 204 | + * @throws LoggerException |
|
| 205 | + */ |
|
| 206 | + private function parseModifiers($modifiers) { |
|
| 207 | + $info = new Payone_Log4php_LoggerFormattingInfo(); |
|
| 208 | + |
|
| 209 | + // If no modifiers are given, return default values |
|
| 210 | + if (empty($modifiers)) { |
|
| 211 | + return $info; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // Validate |
|
| 215 | + $pattern = '/^(-?[0-9]+)?\.?-?[0-9]+$/'; |
|
| 216 | + if (!preg_match($pattern, $modifiers)) { |
|
| 217 | + trigger_error("log4php: Invalid modifier in conversion pattern: [$modifiers]. Ignoring modifier.", E_USER_WARNING); |
|
| 218 | + return $info; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + $parts = explode('.', $modifiers); |
|
| 222 | + |
|
| 223 | + if (!empty($parts[0])) { |
|
| 224 | + $minPart = (integer) $parts[0]; |
|
| 225 | + $info->min = abs($minPart); |
|
| 226 | + $info->padLeft = ($minPart > 0); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if (!empty($parts[1])) { |
|
| 230 | + $maxPart = (integer) $parts[1]; |
|
| 231 | + $info->max = abs($maxPart); |
|
| 232 | + $info->trimLeft = ($maxPart > 0); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return $info; |
|
| 236 | + } |
|
| 237 | 237 | } |
| 238 | 238 | |
@@ -60,12 +60,12 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | // Construct the regex pattern |
| 62 | 62 | $this->regex = |
| 63 | - '/' . // Starting regex pattern delimiter |
|
| 64 | - self::ESCAPE_CHAR . // Character which marks the start of the conversion pattern |
|
| 63 | + '/' . // Starting regex pattern delimiter |
|
| 64 | + self::ESCAPE_CHAR . // Character which marks the start of the conversion pattern |
|
| 65 | 65 | '(?P<modifiers>[0-9.-]*)' . // Format modifiers (optional) |
| 66 | - '(?P<word>[a-zA-Z]+)' . // The conversion word |
|
| 67 | - '(?P<option>{[^}]*})?' . // Conversion option in braces (optional) |
|
| 68 | - '/'; // Ending regex pattern delimiter |
|
| 66 | + '(?P<word>[a-zA-Z]+)' . // The conversion word |
|
| 67 | + '(?P<option>{[^}]*})?' . // Conversion option in braces (optional) |
|
| 68 | + '/'; // Ending regex pattern delimiter |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | $prevEnd = 0; |
| 93 | 93 | |
| 94 | - foreach($matches[0] as $key => $item) { |
|
| 94 | + foreach ($matches[0] as $key => $item) { |
|
| 95 | 95 | |
| 96 | 96 | // Locate where the conversion command starts and ends |
| 97 | 97 | $length = strlen($item[0]); |
@@ -172,12 +172,12 @@ discard block |
||
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | $converterClass = $this->converterMap[$word]; |
| 175 | - if(!class_exists($converterClass)) { |
|
| 175 | + if (!class_exists($converterClass)) { |
|
| 176 | 176 | throw new Payone_Log4php_LoggerException("Class '$converterClass' does not exist."); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | $converter = new $converterClass($info, $option); |
| 180 | - if(!($converter instanceof Payone_Log4php_LoggerPatternConverter)) { |
|
| 180 | + if (!($converter instanceof Payone_Log4php_LoggerPatternConverter)) { |
|
| 181 | 181 | throw new Payone_Log4php_LoggerException("Class '$converterClass' is not an instance of Payone_Log4php_LoggerPatternConverter."); |
| 182 | 182 | } |
| 183 | 183 | |
@@ -221,13 +221,13 @@ discard block |
||
| 221 | 221 | $parts = explode('.', $modifiers); |
| 222 | 222 | |
| 223 | 223 | if (!empty($parts[0])) { |
| 224 | - $minPart = (integer) $parts[0]; |
|
| 224 | + $minPart = (integer)$parts[0]; |
|
| 225 | 225 | $info->min = abs($minPart); |
| 226 | 226 | $info->padLeft = ($minPart > 0); |
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | if (!empty($parts[1])) { |
| 230 | - $maxPart = (integer) $parts[1]; |
|
| 230 | + $maxPart = (integer)$parts[1]; |
|
| 231 | 231 | $info->max = abs($maxPart); |
| 232 | 232 | $info->trimLeft = ($maxPart > 0); |
| 233 | 233 | } |
@@ -123,7 +123,7 @@ |
||
| 123 | 123 | /** |
| 124 | 124 | * Creates an instances from the given class name. |
| 125 | 125 | * |
| 126 | - * @param string $classname |
|
| 126 | + * @param string $class |
|
| 127 | 127 | * @return an object from the class with the given classname |
| 128 | 128 | */ |
| 129 | 129 | public static function createObject($class) { |
@@ -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 | } |
@@ -69,14 +69,14 @@ discard block |
||
| 69 | 69 | public function setProperties($properties, $prefix) { |
| 70 | 70 | $len = strlen($prefix); |
| 71 | 71 | reset($properties); |
| 72 | - while(list($key,) = each($properties)) { |
|
| 73 | - if(strpos($key, $prefix) === 0) { |
|
| 74 | - if(strpos($key, '.', ($len + 1)) > 0) { |
|
| 72 | + while (list($key,) = each($properties)) { |
|
| 73 | + if (strpos($key, $prefix) === 0) { |
|
| 74 | + if (strpos($key, '.', ($len + 1)) > 0) { |
|
| 75 | 75 | continue; |
| 76 | 76 | } |
| 77 | 77 | $value = Payone_Log4php_LoggerOptionConverter::findAndSubst($key, $properties); |
| 78 | 78 | $key = substr($key, $len); |
| 79 | - if($key == 'layout' and ($this->obj instanceof Payone_Log4php_LoggerAppender)) { |
|
| 79 | + if ($key == 'layout' and ($this->obj instanceof Payone_Log4php_LoggerAppender)) { |
|
| 80 | 80 | continue; |
| 81 | 81 | } |
| 82 | 82 | $this->setProperty($key, $value); |
@@ -101,21 +101,21 @@ discard block |
||
| 101 | 101 | * @param string $value String value of the property |
| 102 | 102 | */ |
| 103 | 103 | public function setProperty($name, $value) { |
| 104 | - if($value === null) { |
|
| 104 | + if ($value === null) { |
|
| 105 | 105 | return; |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 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)."!"); |
|
| 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 | 112 | } else { |
| 113 | 113 | return call_user_func(array($this->obj, $method), $value); |
| 114 | 114 | } |
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | public function activate() { |
| 118 | - if(method_exists($this->obj, 'activateoptions')) { |
|
| 118 | + if (method_exists($this->obj, 'activateoptions')) { |
|
| 119 | 119 | return call_user_func(array($this->obj, 'activateoptions')); |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | * @return an object from the class with the given classname |
| 128 | 128 | */ |
| 129 | 129 | public static function createObject($class) { |
| 130 | - if(!empty($class)) { |
|
| 130 | + if (!empty($class)) { |
|
| 131 | 131 | return new $class(); |
| 132 | 132 | } |
| 133 | 133 | return null; |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (empty($name)) { |
| 143 | 143 | return false; |
| 144 | 144 | } |
| 145 | - $methodName = 'set'.ucfirst($name); |
|
| 145 | + $methodName = 'set' . ucfirst($name); |
|
| 146 | 146 | if (method_exists($object, $methodName)) { |
| 147 | 147 | return call_user_func(array($object, $methodName), $value); |
| 148 | 148 | } else { |
@@ -58,7 +58,6 @@ discard block |
||
| 58 | 58 | * Add a renderer to a hierarchy passed as parameter. |
| 59 | 59 | * Note that hierarchy must implement getRendererMap() and setRenderer() methods. |
| 60 | 60 | * |
| 61 | - * @param Payone_Log4php_LoggerHierarchy $repository a logger repository. |
|
| 62 | 61 | * @param string $renderedClassName |
| 63 | 62 | * @param string $renderingClassName |
| 64 | 63 | */ |
@@ -107,7 +106,7 @@ discard block |
||
| 107 | 106 | * class of the object parameter. |
| 108 | 107 | * |
| 109 | 108 | * @param mixed $o |
| 110 | - * @return string |
|
| 109 | + * @return Payone_Log4php_LoggerRendererObject |
|
| 111 | 110 | */ |
| 112 | 111 | public function getByObject($o) { |
| 113 | 112 | return ($o == null) ? null : $this->getByClassName(get_class($o)); |
@@ -36,114 +36,114 @@ |
||
| 36 | 36 | */ |
| 37 | 37 | class Payone_Log4php_LoggerRendererMap { |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @var array |
|
| 41 | - */ |
|
| 42 | - private $map; |
|
| 39 | + /** |
|
| 40 | + * @var array |
|
| 41 | + */ |
|
| 42 | + private $map; |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * @var LoggerDefaultRenderer |
|
| 46 | - */ |
|
| 47 | - private $defaultRenderer; |
|
| 44 | + /** |
|
| 45 | + * @var LoggerDefaultRenderer |
|
| 46 | + */ |
|
| 47 | + private $defaultRenderer; |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Constructor |
|
| 51 | - */ |
|
| 52 | - public function __construct() { |
|
| 53 | - $this->map = array(); |
|
| 54 | - $this->defaultRenderer = new Payone_Log4php_LoggerRendererDefault(); |
|
| 55 | - } |
|
| 49 | + /** |
|
| 50 | + * Constructor |
|
| 51 | + */ |
|
| 52 | + public function __construct() { |
|
| 53 | + $this->map = array(); |
|
| 54 | + $this->defaultRenderer = new Payone_Log4php_LoggerRendererDefault(); |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * Add a renderer to a hierarchy passed as parameter. |
|
| 59 | - * Note that hierarchy must implement getRendererMap() and setRenderer() methods. |
|
| 60 | - * |
|
| 61 | - * @param Payone_Log4php_LoggerHierarchy $repository a logger repository. |
|
| 62 | - * @param string $renderedClassName |
|
| 63 | - * @param string $renderingClassName |
|
| 64 | - */ |
|
| 65 | - public function addRenderer($renderedClassName, $renderingClassName) { |
|
| 66 | - $renderer = Payone_Log4php_LoggerReflectionUtils::createObject($renderingClassName); |
|
| 67 | - if($renderer == null) { |
|
| 68 | - return; |
|
| 69 | - } else { |
|
| 70 | - $this->put($renderedClassName, $renderer); |
|
| 71 | - } |
|
| 72 | - } |
|
| 57 | + /** |
|
| 58 | + * Add a renderer to a hierarchy passed as parameter. |
|
| 59 | + * Note that hierarchy must implement getRendererMap() and setRenderer() methods. |
|
| 60 | + * |
|
| 61 | + * @param Payone_Log4php_LoggerHierarchy $repository a logger repository. |
|
| 62 | + * @param string $renderedClassName |
|
| 63 | + * @param string $renderingClassName |
|
| 64 | + */ |
|
| 65 | + public function addRenderer($renderedClassName, $renderingClassName) { |
|
| 66 | + $renderer = Payone_Log4php_LoggerReflectionUtils::createObject($renderingClassName); |
|
| 67 | + if($renderer == null) { |
|
| 68 | + return; |
|
| 69 | + } else { |
|
| 70 | + $this->put($renderedClassName, $renderer); |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Find the appropriate renderer for the class type of the |
|
| 77 | - * <var>o</var> parameter. |
|
| 78 | - * |
|
| 79 | - * This is accomplished by calling the {@link getByObject()} |
|
| 80 | - * method if <var>o</var> is object or using {@link Payone_Log4php_LoggerRendererDefault}. |
|
| 81 | - * Once a renderer is found, it is applied on the object <var>o</var> and |
|
| 82 | - * the result is returned as a string. |
|
| 83 | - * |
|
| 84 | - * @param mixed $o |
|
| 85 | - * @return string |
|
| 86 | - */ |
|
| 87 | - public function findAndRender($o) { |
|
| 88 | - if($o == null) { |
|
| 89 | - return null; |
|
| 90 | - } else { |
|
| 91 | - if(is_object($o)) { |
|
| 92 | - $renderer = $this->getByObject($o); |
|
| 93 | - if($renderer !== null) { |
|
| 94 | - return $renderer->render($o); |
|
| 95 | - } else { |
|
| 96 | - return null; |
|
| 97 | - } |
|
| 98 | - } else { |
|
| 99 | - $renderer = $this->defaultRenderer; |
|
| 100 | - return $renderer->render($o); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } |
|
| 75 | + /** |
|
| 76 | + * Find the appropriate renderer for the class type of the |
|
| 77 | + * <var>o</var> parameter. |
|
| 78 | + * |
|
| 79 | + * This is accomplished by calling the {@link getByObject()} |
|
| 80 | + * method if <var>o</var> is object or using {@link Payone_Log4php_LoggerRendererDefault}. |
|
| 81 | + * Once a renderer is found, it is applied on the object <var>o</var> and |
|
| 82 | + * the result is returned as a string. |
|
| 83 | + * |
|
| 84 | + * @param mixed $o |
|
| 85 | + * @return string |
|
| 86 | + */ |
|
| 87 | + public function findAndRender($o) { |
|
| 88 | + if($o == null) { |
|
| 89 | + return null; |
|
| 90 | + } else { |
|
| 91 | + if(is_object($o)) { |
|
| 92 | + $renderer = $this->getByObject($o); |
|
| 93 | + if($renderer !== null) { |
|
| 94 | + return $renderer->render($o); |
|
| 95 | + } else { |
|
| 96 | + return null; |
|
| 97 | + } |
|
| 98 | + } else { |
|
| 99 | + $renderer = $this->defaultRenderer; |
|
| 100 | + return $renderer->render($o); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Syntactic sugar method that calls {@link PHP_MANUAL#get_class} with the |
|
| 107 | - * class of the object parameter. |
|
| 108 | - * |
|
| 109 | - * @param mixed $o |
|
| 110 | - * @return string |
|
| 111 | - */ |
|
| 112 | - public function getByObject($o) { |
|
| 113 | - return ($o == null) ? null : $this->getByClassName(get_class($o)); |
|
| 114 | - } |
|
| 105 | + /** |
|
| 106 | + * Syntactic sugar method that calls {@link PHP_MANUAL#get_class} with the |
|
| 107 | + * class of the object parameter. |
|
| 108 | + * |
|
| 109 | + * @param mixed $o |
|
| 110 | + * @return string |
|
| 111 | + */ |
|
| 112 | + public function getByObject($o) { |
|
| 113 | + return ($o == null) ? null : $this->getByClassName(get_class($o)); |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * Search the parents of <var>clazz</var> for a renderer. |
|
| 119 | - * |
|
| 120 | - * The renderer closest in the hierarchy will be returned. If no |
|
| 121 | - * renderers could be found, then the default renderer is returned. |
|
| 122 | - * |
|
| 123 | - * @param string $class |
|
| 124 | - * @return Payone_Log4php_LoggerRendererObject |
|
| 125 | - */ |
|
| 126 | - public function getByClassName($class) { |
|
| 127 | - $r = null; |
|
| 128 | - for($c = $class; !empty($c); $c = get_parent_class($c)) { |
|
| 129 | - $c = strtolower($c); |
|
| 130 | - if(isset($this->map[$c])) { |
|
| 131 | - return $this->map[$c]; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - return $this->defaultRenderer; |
|
| 135 | - } |
|
| 117 | + /** |
|
| 118 | + * Search the parents of <var>clazz</var> for a renderer. |
|
| 119 | + * |
|
| 120 | + * The renderer closest in the hierarchy will be returned. If no |
|
| 121 | + * renderers could be found, then the default renderer is returned. |
|
| 122 | + * |
|
| 123 | + * @param string $class |
|
| 124 | + * @return Payone_Log4php_LoggerRendererObject |
|
| 125 | + */ |
|
| 126 | + public function getByClassName($class) { |
|
| 127 | + $r = null; |
|
| 128 | + for($c = $class; !empty($c); $c = get_parent_class($c)) { |
|
| 129 | + $c = strtolower($c); |
|
| 130 | + if(isset($this->map[$c])) { |
|
| 131 | + return $this->map[$c]; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + return $this->defaultRenderer; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - public function clear() { |
|
| 138 | - $this->map = array(); |
|
| 139 | - } |
|
| 137 | + public function clear() { |
|
| 138 | + $this->map = array(); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Register a {@link Payone_Log4php_LoggerRendererObject} for <var>clazz</var>. |
|
| 143 | - * @param string $class |
|
| 144 | - * @param Payone_Log4php_LoggerRendererObject $or |
|
| 145 | - */ |
|
| 146 | - private function put($class, $or) { |
|
| 147 | - $this->map[strtolower($class)] = $or; |
|
| 148 | - } |
|
| 141 | + /** |
|
| 142 | + * Register a {@link Payone_Log4php_LoggerRendererObject} for <var>clazz</var>. |
|
| 143 | + * @param string $class |
|
| 144 | + * @param Payone_Log4php_LoggerRendererObject $or |
|
| 145 | + */ |
|
| 146 | + private function put($class, $or) { |
|
| 147 | + $this->map[strtolower($class)] = $or; |
|
| 148 | + } |
|
| 149 | 149 | } |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | */ |
| 65 | 65 | public function addRenderer($renderedClassName, $renderingClassName) { |
| 66 | 66 | $renderer = Payone_Log4php_LoggerReflectionUtils::createObject($renderingClassName); |
| 67 | - if($renderer == null) { |
|
| 67 | + if ($renderer == null) { |
|
| 68 | 68 | return; |
| 69 | 69 | } else { |
| 70 | 70 | $this->put($renderedClassName, $renderer); |
@@ -85,12 +85,12 @@ discard block |
||
| 85 | 85 | * @return string |
| 86 | 86 | */ |
| 87 | 87 | public function findAndRender($o) { |
| 88 | - if($o == null) { |
|
| 88 | + if ($o == null) { |
|
| 89 | 89 | return null; |
| 90 | 90 | } else { |
| 91 | - if(is_object($o)) { |
|
| 91 | + if (is_object($o)) { |
|
| 92 | 92 | $renderer = $this->getByObject($o); |
| 93 | - if($renderer !== null) { |
|
| 93 | + if ($renderer !== null) { |
|
| 94 | 94 | return $renderer->render($o); |
| 95 | 95 | } else { |
| 96 | 96 | return null; |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | public function getByClassName($class) { |
| 127 | 127 | $r = null; |
| 128 | - for($c = $class; !empty($c); $c = get_parent_class($c)) { |
|
| 128 | + for ($c = $class; !empty($c); $c = get_parent_class($c)) { |
|
| 129 | 129 | $c = strtolower($c); |
| 130 | - if(isset($this->map[$c])) { |
|
| 130 | + if (isset($this->map[$c])) { |
|
| 131 | 131 | return $this->map[$c]; |
| 132 | 132 | } |
| 133 | 133 | } |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | /** |
| 61 | 61 | * Always returns false. |
| 62 | 62 | * Because LoggerRoot has no parents, it returns false. |
| 63 | - * @param Logger $parent |
|
| 63 | + * @param Payone_Log4php_Logger $parent |
|
| 64 | 64 | * @return boolean |
| 65 | 65 | */ |
| 66 | 66 | public function setParent(Payone_Log4php_Logger $parent) { |
@@ -26,45 +26,45 @@ |
||
| 26 | 26 | * @see Logger |
| 27 | 27 | */ |
| 28 | 28 | class Payone_Log4php_LoggerRoot extends Payone_Log4php_Logger { |
| 29 | - /** |
|
| 30 | - * Constructor |
|
| 31 | - * |
|
| 32 | - * @param integer $level initial log level |
|
| 33 | - */ |
|
| 34 | - public function __construct($level = null) { |
|
| 35 | - parent::__construct('root'); |
|
| 29 | + /** |
|
| 30 | + * Constructor |
|
| 31 | + * |
|
| 32 | + * @param integer $level initial log level |
|
| 33 | + */ |
|
| 34 | + public function __construct($level = null) { |
|
| 35 | + parent::__construct('root'); |
|
| 36 | 36 | |
| 37 | - if($level == null) { |
|
| 38 | - $level = Payone_Log4php_LoggerLevel::getLevelAll(); |
|
| 39 | - } |
|
| 40 | - $this->setLevel($level); |
|
| 41 | - } |
|
| 37 | + if($level == null) { |
|
| 38 | + $level = Payone_Log4php_LoggerLevel::getLevelAll(); |
|
| 39 | + } |
|
| 40 | + $this->setLevel($level); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return Payone_Log4php_LoggerLevel the level |
|
| 45 | - */ |
|
| 46 | - public function getChainedLevel() { |
|
| 47 | - return parent::getLevel(); |
|
| 48 | - } |
|
| 43 | + /** |
|
| 44 | + * @return Payone_Log4php_LoggerLevel the level |
|
| 45 | + */ |
|
| 46 | + public function getChainedLevel() { |
|
| 47 | + return parent::getLevel(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * Setting a null value to the level of the root category may have catastrophic results. |
|
| 52 | - * @param Payone_Log4php_LoggerLevel $level |
|
| 53 | - */ |
|
| 54 | - public function setLevel($level) { |
|
| 55 | - if($level != null) { |
|
| 56 | - parent::setLevel($level); |
|
| 57 | - } |
|
| 58 | - } |
|
| 50 | + /** |
|
| 51 | + * Setting a null value to the level of the root category may have catastrophic results. |
|
| 52 | + * @param Payone_Log4php_LoggerLevel $level |
|
| 53 | + */ |
|
| 54 | + public function setLevel($level) { |
|
| 55 | + if($level != null) { |
|
| 56 | + parent::setLevel($level); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Always returns false. |
|
| 62 | - * Because LoggerRoot has no parents, it returns false. |
|
| 63 | - * @param Logger $parent |
|
| 64 | - * @return boolean |
|
| 65 | - */ |
|
| 66 | - public function setParent(Payone_Log4php_Logger $parent) { |
|
| 67 | - return false; |
|
| 68 | - } |
|
| 60 | + /** |
|
| 61 | + * Always returns false. |
|
| 62 | + * Because LoggerRoot has no parents, it returns false. |
|
| 63 | + * @param Logger $parent |
|
| 64 | + * @return boolean |
|
| 65 | + */ |
|
| 66 | + public function setParent(Payone_Log4php_Logger $parent) { |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | } |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | public function __construct($level = null) { |
| 35 | 35 | parent::__construct('root'); |
| 36 | 36 | |
| 37 | - if($level == null) { |
|
| 37 | + if ($level == null) { |
|
| 38 | 38 | $level = Payone_Log4php_LoggerLevel::getLevelAll(); |
| 39 | 39 | } |
| 40 | 40 | $this->setLevel($level); |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @param Payone_Log4php_LoggerLevel $level |
| 53 | 53 | */ |
| 54 | 54 | public function setLevel($level) { |
| 55 | - if($level != null) { |
|
| 55 | + if ($level != null) { |
|
| 56 | 56 | parent::setLevel($level); |
| 57 | 57 | } |
| 58 | 58 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @api |
| 50 | 50 | * |
| 51 | 51 | * @param Payone_Settings_Data_ConfigFile_Root $config |
| 52 | - * @return mixed @see SimpleXMLElement::asXml() |
|
| 52 | + * @return string @see SimpleXMLElement::asXml() |
|
| 53 | 53 | */ |
| 54 | 54 | public function generate(Payone_Settings_Data_ConfigFile_Root $config) |
| 55 | 55 | { |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @api |
| 75 | 75 | * |
| 76 | 76 | * @param Payone_Settings_Data_ConfigFile_Root $config |
| 77 | - * @return mixed @see SimpleXMLElement::asXml() |
|
| 77 | + * @return string|false @see SimpleXMLElement::asXml() |
|
| 78 | 78 | */ |
| 79 | 79 | public function execute(Payone_Settings_Data_ConfigFile_Root $config) |
| 80 | 80 | { |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | /** |
| 126 | 126 | * @param Payone_Settings_Data_ConfigFile_Shop $shopConfig |
| 127 | 127 | * @param DOMElement $configXml |
| 128 | - * @return string |
|
| 128 | + * @return DOMElement |
|
| 129 | 129 | */ |
| 130 | 130 | protected function mapShop(Payone_Settings_Data_ConfigFile_Shop $shopConfig, DOMElement $configXml) |
| 131 | 131 | { |
@@ -366,6 +366,10 @@ discard block |
||
| 366 | 366 | $this->addGlobal($cleatringTypeNode, $valueClearingType); |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | + /** |
|
| 370 | + * @param DOMElement $parent |
|
| 371 | + * @param Payone_Settings_Data_ConfigFile_PaymentMethod_Abstract $type |
|
| 372 | + */ |
|
| 369 | 373 | public function addGlobal($parent, $type) |
| 370 | 374 | { |
| 371 | 375 | |
@@ -401,7 +405,7 @@ discard block |
||
| 401 | 405 | /** |
| 402 | 406 | * @param DOMElement $parent |
| 403 | 407 | * @param $object |
| 404 | - * @param $property |
|
| 408 | + * @param string $property |
|
| 405 | 409 | * @param bool $withCdata |
| 406 | 410 | * @return DOMElement |
| 407 | 411 | */ |
@@ -173,9 +173,9 @@ discard block |
||
| 173 | 173 | $this->addChild($globalXml, $globalConfig, 'aid'); |
| 174 | 174 | $this->addChild($globalXml, $globalConfig, 'portalid'); |
| 175 | 175 | $this->addChild($globalXml, $globalConfig, 'request_type'); |
| 176 | - $this->mapParameterInvoice($globalConfig,$globalXml); |
|
| 176 | + $this->mapParameterInvoice($globalConfig, $globalXml); |
|
| 177 | 177 | $this->addStatusMapping($globalConfig, $globalXml); |
| 178 | - $this->mapPaymentCreditcard($globalConfig,$globalXml); |
|
| 178 | + $this->mapPaymentCreditcard($globalConfig, $globalXml); |
|
| 179 | 179 | return $shopXml; |
| 180 | 180 | } |
| 181 | 181 | |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | */ |
| 215 | 215 | protected function mapProtect(Payone_Settings_Data_ConfigFile_Shop_Protect $protectConfig, DOMElement $shopXml) |
| 216 | 216 | { |
| 217 | - $protectXml = $this->appendElement($shopXml,$protectConfig->getKey()); |
|
| 217 | + $protectXml = $this->appendElement($shopXml, $protectConfig->getKey()); |
|
| 218 | 218 | |
| 219 | 219 | $protectXml = $this->mapConsumerscore($protectConfig->getConsumerscore(), $protectXml); |
| 220 | 220 | $protectXml = $this->mapAddresscheck($protectConfig->getAddresscheck(), $protectXml); |
@@ -321,7 +321,7 @@ discard block |
||
| 321 | 321 | $tasXml = $this->appendElement($miscXml, $tasForwarding->getKey()); |
| 322 | 322 | |
| 323 | 323 | foreach ($tasForwarding->getTransactionstatusForwarding() as $keyTas => $config) { |
| 324 | - $configNode = $this->appendElement($tasXml,'config'); |
|
| 324 | + $configNode = $this->appendElement($tasXml, 'config'); |
|
| 325 | 325 | |
| 326 | 326 | foreach ($config as $key => $value) { |
| 327 | 327 | $configNode->setAttribute($key, $value); |
@@ -336,10 +336,10 @@ discard block |
||
| 336 | 336 | public function addStatusMapping(Payone_Settings_Data_ConfigFile_Shop_Global $globalConfig, DOMElement $globalXml) |
| 337 | 337 | { |
| 338 | 338 | $statusMapping = $globalConfig->getStatusMapping(); |
| 339 | - $tasXml = $this->appendElement($globalXml,$statusMapping->getKey()); |
|
| 339 | + $tasXml = $this->appendElement($globalXml, $statusMapping->getKey()); |
|
| 340 | 340 | |
| 341 | 341 | foreach ($statusMapping->getStatusMapping() as $keyStatusMapping => $valueStatusMapping) { |
| 342 | - $parent = $this->appendElement($tasXml,$keyStatusMapping); |
|
| 342 | + $parent = $this->appendElement($tasXml, $keyStatusMapping); |
|
| 343 | 343 | |
| 344 | 344 | foreach ($valueStatusMapping as $key => $value) { |
| 345 | 345 | $mapNode = $this->appendElement($parent, 'map'); |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | { |
| 386 | 386 | $feeConfig = $valueClearingType->getFeeConfig(); |
| 387 | 387 | if (!empty($feeConfig)) { |
| 388 | - $feeConfigNode = $this->appendElement($cleatringTypeNode,'fee_config'); |
|
| 388 | + $feeConfigNode = $this->appendElement($cleatringTypeNode, 'fee_config'); |
|
| 389 | 389 | |
| 390 | 390 | foreach ($feeConfig as $keyFeeConfig => $valueFeeConfig) { |
| 391 | 391 | if (array_key_exists('value', $valueFeeConfig) && array_key_exists('attribute', $valueFeeConfig)) { |
@@ -411,7 +411,7 @@ discard block |
||
| 411 | 411 | $data = $object->$getter(); |
| 412 | 412 | $child = $parent; |
| 413 | 413 | if (is_array($data)) { |
| 414 | - $parentNode = $this->appendElement($parent,$property); |
|
| 414 | + $parentNode = $this->appendElement($parent, $property); |
|
| 415 | 415 | foreach ($data as $key => $value) { |
| 416 | 416 | $child = $this->appendElement($parentNode, $key, $value, $withCdata); |
| 417 | 417 | } |
@@ -452,9 +452,9 @@ discard block |
||
| 452 | 452 | * @param bool $asCdata |
| 453 | 453 | * @return DOMElement |
| 454 | 454 | */ |
| 455 | - protected function appendElement( $parent, $key, $value = null, $asCdata = false) |
|
| 455 | + protected function appendElement($parent, $key, $value = null, $asCdata = false) |
|
| 456 | 456 | { |
| 457 | - if($asCdata === true) |
|
| 457 | + if ($asCdata === true) |
|
| 458 | 458 | { |
| 459 | 459 | $cdata = $this->dom->createCDATASection($value); |
| 460 | 460 | $child = $this->dom->createElement($key); |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | else |
| 464 | 464 | { |
| 465 | 465 | $child = $this->dom->createElement($key); |
| 466 | - if($value !== null) |
|
| 466 | + if ($value !== null) |
|
| 467 | 467 | { |
| 468 | 468 | $domValue = $this->dom->createTextNode($value); |
| 469 | 469 | $child->appendChild($domValue); |
@@ -109,12 +109,10 @@ discard block |
||
| 109 | 109 | foreach ($value['attribute'] as $attributKey => $attributData) { |
| 110 | 110 | $node->addAttribute($attributKey, $attributData); |
| 111 | 111 | } |
| 112 | - } |
|
| 113 | - else { |
|
| 112 | + } else { |
|
| 114 | 113 | $this->simpleXmlFromNestedArray($key, $value, $parent); |
| 115 | 114 | } |
| 116 | - } |
|
| 117 | - else { |
|
| 115 | + } else { |
|
| 118 | 116 | $parent->addChild($key, $value); |
| 119 | 117 | } |
| 120 | 118 | |
@@ -415,8 +413,7 @@ discard block |
||
| 415 | 413 | foreach ($data as $key => $value) { |
| 416 | 414 | $child = $this->appendElement($parentNode, $key, $value, $withCdata); |
| 417 | 415 | } |
| 418 | - } |
|
| 419 | - else { |
|
| 416 | + } else { |
|
| 420 | 417 | if (isset($data)) { |
| 421 | 418 | $child = $this->appendElement($parent, $property, $data, $withCdata); |
| 422 | 419 | } |
@@ -436,8 +433,7 @@ discard block |
||
| 436 | 433 | foreach ($value as $key => $data) { |
| 437 | 434 | $mapNode->setAttribute($key, $data); |
| 438 | 435 | } |
| 439 | - } |
|
| 440 | - else { |
|
| 436 | + } else { |
|
| 441 | 437 | if (!empty($data)) { |
| 442 | 438 | $mapNode->setAttribute($name, $value); |
| 443 | 439 | } |
@@ -459,8 +455,7 @@ discard block |
||
| 459 | 455 | $cdata = $this->dom->createCDATASection($value); |
| 460 | 456 | $child = $this->dom->createElement($key); |
| 461 | 457 | $child->appendChild($cdata); |
| 462 | - } |
|
| 463 | - else |
|
| 458 | + } else |
|
| 464 | 459 | { |
| 465 | 460 | $child = $this->dom->createElement($key); |
| 466 | 461 | if($value !== null) |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | - * @param $key |
|
| 56 | + * @param string $key |
|
| 57 | 57 | * @return Payone_TransactionStatus_Service_HandleRequest |
| 58 | 58 | * @throws Exception |
| 59 | 59 | */ |
@@ -77,8 +77,7 @@ discard block |
||
| 77 | 77 | { |
| 78 | 78 | if (empty($data)) { |
| 79 | 79 | $this->config = $this->getDefaultConfigData(); |
| 80 | - } |
|
| 81 | - else { |
|
| 80 | + } else { |
|
| 82 | 81 | $this->config = $data; |
| 83 | 82 | } |
| 84 | 83 | } |
@@ -127,8 +126,7 @@ discard block |
||
| 127 | 126 | // Start recursion: |
| 128 | 127 | return $this->set($newKey, $value, $tree[$currentKey]); |
| 129 | 128 | |
| 130 | - } |
|
| 131 | - else { |
|
| 129 | + } else { |
|
| 132 | 130 | // Set value (can overwrite an existing value) |
| 133 | 131 | $tree[$key] = $value; |
| 134 | 132 | // Exit recursion, Success! |
@@ -166,16 +164,13 @@ discard block |
||
| 166 | 164 | // Reassemble key, start recursion: |
| 167 | 165 | $newKey = implode(self::KEY_SEPARATOR, $explodedKey); |
| 168 | 166 | return $this->get($newKey, $newTree); |
| 169 | - } |
|
| 170 | - else { |
|
| 167 | + } else { |
|
| 171 | 168 | return NULL; // Exit recursion, unsuccessful |
| 172 | 169 | } |
| 173 | 170 | |
| 174 | - } |
|
| 175 | - elseif (is_array($tree) and array_key_exists($key, $tree)) { |
|
| 171 | + } elseif (is_array($tree) and array_key_exists($key, $tree)) { |
|
| 176 | 172 | return $tree[$key]; // Exit recursion, Success! |
| 177 | - } |
|
| 178 | - else { |
|
| 173 | + } else { |
|
| 179 | 174 | return NULL; // Exit recursion, unsuccessful |
| 180 | 175 | } |
| 181 | 176 | } |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | /** |
| 51 | 51 | * @param $value |
| 52 | 52 | */ |
| 53 | - public function addStatusMapping($key,$value) |
|
| 53 | + public function addStatusMapping($key, $value) |
|
| 54 | 54 | { |
| 55 | 55 | $this->status_mapping[$key] = $value; |
| 56 | 56 | } |
@@ -52,7 +52,7 @@ |
||
| 52 | 52 | protected $parameter_invoice = array(); |
| 53 | 53 | |
| 54 | 54 | /** @var Payone_Settings_Data_ConfigFile_Global_StatusMapping */ |
| 55 | - protected $status_mapping = null ; |
|
| 55 | + protected $status_mapping = null; |
|
| 56 | 56 | |
| 57 | 57 | /** @var array */ |
| 58 | 58 | protected $payment_creditcard = array(); |