@@ -112,7 +112,7 @@ |
||
| 112 | 112 | |
| 113 | 113 | /** |
| 114 | 114 | * Never use this method directly, use the {@link LoggerLoggingEvent::getNDC()} method instead. |
| 115 | - * @return array |
|
| 115 | + * @return string |
|
| 116 | 116 | */ |
| 117 | 117 | public static function get() { |
| 118 | 118 | return implode(' ', self::$stack); |
@@ -95,109 +95,109 @@ |
||
| 95 | 95 | */ |
| 96 | 96 | class Payone_Log4php_LoggerNDC { |
| 97 | 97 | |
| 98 | - /** This is the repository of NDC stack */ |
|
| 99 | - private static $stack = array(); |
|
| 98 | + /** This is the repository of NDC stack */ |
|
| 99 | + private static $stack = array(); |
|
| 100 | 100 | |
| 101 | - /** |
|
| 102 | - * Clear any nested diagnostic information if any. This method is |
|
| 103 | - * useful in cases where the same thread can be potentially used |
|
| 104 | - * over and over in different unrelated contexts. |
|
| 105 | - * |
|
| 106 | - * <p>This method is equivalent to calling the {@link setMaxDepth()} |
|
| 107 | - * method with a zero <var>maxDepth</var> argument. |
|
| 108 | - */ |
|
| 109 | - public static function clear() { |
|
| 110 | - self::$stack = array(); |
|
| 111 | - } |
|
| 101 | + /** |
|
| 102 | + * Clear any nested diagnostic information if any. This method is |
|
| 103 | + * useful in cases where the same thread can be potentially used |
|
| 104 | + * over and over in different unrelated contexts. |
|
| 105 | + * |
|
| 106 | + * <p>This method is equivalent to calling the {@link setMaxDepth()} |
|
| 107 | + * method with a zero <var>maxDepth</var> argument. |
|
| 108 | + */ |
|
| 109 | + public static function clear() { |
|
| 110 | + self::$stack = array(); |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - /** |
|
| 114 | - * Never use this method directly, use the {@link LoggerLoggingEvent::getNDC()} method instead. |
|
| 115 | - * @return array |
|
| 116 | - */ |
|
| 117 | - public static function get() { |
|
| 118 | - return implode(' ', self::$stack); |
|
| 119 | - } |
|
| 113 | + /** |
|
| 114 | + * Never use this method directly, use the {@link LoggerLoggingEvent::getNDC()} method instead. |
|
| 115 | + * @return array |
|
| 116 | + */ |
|
| 117 | + public static function get() { |
|
| 118 | + return implode(' ', self::$stack); |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | - /** |
|
| 122 | - * Get the current nesting depth of this diagnostic context. |
|
| 123 | - * |
|
| 124 | - * @see setMaxDepth() |
|
| 125 | - * @return integer |
|
| 126 | - */ |
|
| 127 | - public static function getDepth() { |
|
| 128 | - return count(self::$stack); |
|
| 129 | - } |
|
| 121 | + /** |
|
| 122 | + * Get the current nesting depth of this diagnostic context. |
|
| 123 | + * |
|
| 124 | + * @see setMaxDepth() |
|
| 125 | + * @return integer |
|
| 126 | + */ |
|
| 127 | + public static function getDepth() { |
|
| 128 | + return count(self::$stack); |
|
| 129 | + } |
|
| 130 | 130 | |
| 131 | - /** |
|
| 132 | - * Clients should call this method before leaving a diagnostic |
|
| 133 | - * context. |
|
| 134 | - * |
|
| 135 | - * <p>The returned value is the value that was pushed last. If no |
|
| 136 | - * context is available, then the empty string "" is returned.</p> |
|
| 137 | - * |
|
| 138 | - * @return string The innermost diagnostic context. |
|
| 139 | - */ |
|
| 140 | - public static function pop() { |
|
| 141 | - if(count(self::$stack) > 0) { |
|
| 142 | - return array_pop(self::$stack); |
|
| 143 | - } else { |
|
| 144 | - return ''; |
|
| 145 | - } |
|
| 146 | - } |
|
| 131 | + /** |
|
| 132 | + * Clients should call this method before leaving a diagnostic |
|
| 133 | + * context. |
|
| 134 | + * |
|
| 135 | + * <p>The returned value is the value that was pushed last. If no |
|
| 136 | + * context is available, then the empty string "" is returned.</p> |
|
| 137 | + * |
|
| 138 | + * @return string The innermost diagnostic context. |
|
| 139 | + */ |
|
| 140 | + public static function pop() { |
|
| 141 | + if(count(self::$stack) > 0) { |
|
| 142 | + return array_pop(self::$stack); |
|
| 143 | + } else { |
|
| 144 | + return ''; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Looks at the last diagnostic context at the top of this NDC |
|
| 150 | - * without removing it. |
|
| 151 | - * |
|
| 152 | - * <p>The returned value is the value that was pushed last. If no |
|
| 153 | - * context is available, then the empty string "" is returned.</p> |
|
| 154 | - * @return string The innermost diagnostic context. |
|
| 155 | - */ |
|
| 156 | - public static function peek(){ |
|
| 157 | - if(count(self::$stack) > 0) { |
|
| 158 | - return end(self::$stack); |
|
| 159 | - } else { |
|
| 160 | - return ''; |
|
| 161 | - } |
|
| 162 | - } |
|
| 148 | + /** |
|
| 149 | + * Looks at the last diagnostic context at the top of this NDC |
|
| 150 | + * without removing it. |
|
| 151 | + * |
|
| 152 | + * <p>The returned value is the value that was pushed last. If no |
|
| 153 | + * context is available, then the empty string "" is returned.</p> |
|
| 154 | + * @return string The innermost diagnostic context. |
|
| 155 | + */ |
|
| 156 | + public static function peek(){ |
|
| 157 | + if(count(self::$stack) > 0) { |
|
| 158 | + return end(self::$stack); |
|
| 159 | + } else { |
|
| 160 | + return ''; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Push new diagnostic context information for the current thread. |
|
| 166 | - * |
|
| 167 | - * <p>The contents of the <var>message</var> parameter is |
|
| 168 | - * determined solely by the client. |
|
| 169 | - * |
|
| 170 | - * @param string $message The new diagnostic context information. |
|
| 171 | - */ |
|
| 172 | - public static function push($message) { |
|
| 173 | - array_push(self::$stack, (string)$message); |
|
| 174 | - } |
|
| 164 | + /** |
|
| 165 | + * Push new diagnostic context information for the current thread. |
|
| 166 | + * |
|
| 167 | + * <p>The contents of the <var>message</var> parameter is |
|
| 168 | + * determined solely by the client. |
|
| 169 | + * |
|
| 170 | + * @param string $message The new diagnostic context information. |
|
| 171 | + */ |
|
| 172 | + public static function push($message) { |
|
| 173 | + array_push(self::$stack, (string)$message); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Remove the diagnostic context for this thread. |
|
| 178 | - */ |
|
| 179 | - public static function remove() { |
|
| 180 | - Payone_Log4php_LoggerNDC::clear(); |
|
| 181 | - } |
|
| 176 | + /** |
|
| 177 | + * Remove the diagnostic context for this thread. |
|
| 178 | + */ |
|
| 179 | + public static function remove() { |
|
| 180 | + Payone_Log4php_LoggerNDC::clear(); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /** |
|
| 184 | - * Set maximum depth of this diagnostic context. If the current |
|
| 185 | - * depth is smaller or equal to <var>maxDepth</var>, then no |
|
| 186 | - * action is taken. |
|
| 187 | - * |
|
| 188 | - * <p>This method is a convenient alternative to multiple |
|
| 189 | - * {@link pop()} calls. Moreover, it is often the case that at |
|
| 190 | - * the end of complex call sequences, the depth of the NDC is |
|
| 191 | - * unpredictable. The {@link setMaxDepth()} method circumvents |
|
| 192 | - * this problem. |
|
| 193 | - * |
|
| 194 | - * @param integer $maxDepth |
|
| 195 | - * @see getDepth() |
|
| 196 | - */ |
|
| 197 | - public static function setMaxDepth($maxDepth) { |
|
| 198 | - $maxDepth = (int)$maxDepth; |
|
| 199 | - if(Payone_Log4php_LoggerNDC::getDepth() > $maxDepth) { |
|
| 200 | - self::$stack = array_slice(self::$stack, 0, $maxDepth); |
|
| 201 | - } |
|
| 202 | - } |
|
| 183 | + /** |
|
| 184 | + * Set maximum depth of this diagnostic context. If the current |
|
| 185 | + * depth is smaller or equal to <var>maxDepth</var>, then no |
|
| 186 | + * action is taken. |
|
| 187 | + * |
|
| 188 | + * <p>This method is a convenient alternative to multiple |
|
| 189 | + * {@link pop()} calls. Moreover, it is often the case that at |
|
| 190 | + * the end of complex call sequences, the depth of the NDC is |
|
| 191 | + * unpredictable. The {@link setMaxDepth()} method circumvents |
|
| 192 | + * this problem. |
|
| 193 | + * |
|
| 194 | + * @param integer $maxDepth |
|
| 195 | + * @see getDepth() |
|
| 196 | + */ |
|
| 197 | + public static function setMaxDepth($maxDepth) { |
|
| 198 | + $maxDepth = (int)$maxDepth; |
|
| 199 | + if(Payone_Log4php_LoggerNDC::getDepth() > $maxDepth) { |
|
| 200 | + self::$stack = array_slice(self::$stack, 0, $maxDepth); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | * @return string The innermost diagnostic context. |
| 139 | 139 | */ |
| 140 | 140 | public static function pop() { |
| 141 | - if(count(self::$stack) > 0) { |
|
| 141 | + if (count(self::$stack) > 0) { |
|
| 142 | 142 | return array_pop(self::$stack); |
| 143 | 143 | } else { |
| 144 | 144 | return ''; |
@@ -153,8 +153,8 @@ discard block |
||
| 153 | 153 | * context is available, then the empty string "" is returned.</p> |
| 154 | 154 | * @return string The innermost diagnostic context. |
| 155 | 155 | */ |
| 156 | - public static function peek(){ |
|
| 157 | - if(count(self::$stack) > 0) { |
|
| 156 | + public static function peek() { |
|
| 157 | + if (count(self::$stack) > 0) { |
|
| 158 | 158 | return end(self::$stack); |
| 159 | 159 | } else { |
| 160 | 160 | return ''; |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | public static function setMaxDepth($maxDepth) { |
| 198 | 198 | $maxDepth = (int)$maxDepth; |
| 199 | - if(Payone_Log4php_LoggerNDC::getDepth() > $maxDepth) { |
|
| 199 | + if (Payone_Log4php_LoggerNDC::getDepth() > $maxDepth) { |
|
| 200 | 200 | self::$stack = array_slice(self::$stack, 0, $maxDepth); |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -73,6 +73,7 @@ |
||
| 73 | 73 | * converters must implement this method. |
| 74 | 74 | * |
| 75 | 75 | * @param Payone_Log4php_LoggerLoggingEvent $event |
| 76 | + * @return string |
|
| 76 | 77 | */ |
| 77 | 78 | abstract public function convert(Payone_Log4php_LoggerLoggingEvent $event); |
| 78 | 79 | |
@@ -33,99 +33,99 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | abstract class Payone_Log4php_LoggerPatternConverter { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Next converter in the converter chain. |
|
| 38 | - * @var Payone_Log4php_LoggerPatternConverter |
|
| 39 | - */ |
|
| 40 | - public $next = null; |
|
| 36 | + /** |
|
| 37 | + * Next converter in the converter chain. |
|
| 38 | + * @var Payone_Log4php_LoggerPatternConverter |
|
| 39 | + */ |
|
| 40 | + public $next = null; |
|
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * Formatting information, parsed from pattern modifiers. |
|
| 44 | - * @var Payone_Log4php_LoggerFormattingInfo |
|
| 45 | - */ |
|
| 46 | - protected $formattingInfo; |
|
| 42 | + /** |
|
| 43 | + * Formatting information, parsed from pattern modifiers. |
|
| 44 | + * @var Payone_Log4php_LoggerFormattingInfo |
|
| 45 | + */ |
|
| 46 | + protected $formattingInfo; |
|
| 47 | 47 | |
| 48 | - /** |
|
| 49 | - * Converter-specific formatting options. |
|
| 50 | - * @var array |
|
| 51 | - */ |
|
| 52 | - protected $option; |
|
| 48 | + /** |
|
| 49 | + * Converter-specific formatting options. |
|
| 50 | + * @var array |
|
| 51 | + */ |
|
| 52 | + protected $option; |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * Constructor |
|
| 56 | - * @param Payone_Log4php_LoggerFormattingInfo $formattingInfo |
|
| 57 | - * @param array $option |
|
| 58 | - */ |
|
| 59 | - public function __construct(Payone_Log4php_LoggerFormattingInfo $formattingInfo = null, $option = null) { |
|
| 60 | - $this->formattingInfo = $formattingInfo; |
|
| 61 | - $this->option = $option; |
|
| 62 | - $this->activateOptions(); |
|
| 63 | - } |
|
| 54 | + /** |
|
| 55 | + * Constructor |
|
| 56 | + * @param Payone_Log4php_LoggerFormattingInfo $formattingInfo |
|
| 57 | + * @param array $option |
|
| 58 | + */ |
|
| 59 | + public function __construct(Payone_Log4php_LoggerFormattingInfo $formattingInfo = null, $option = null) { |
|
| 60 | + $this->formattingInfo = $formattingInfo; |
|
| 61 | + $this->option = $option; |
|
| 62 | + $this->activateOptions(); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Called in constructor. Converters which need to process the options |
|
| 67 | - * can override this method. |
|
| 68 | - */ |
|
| 69 | - public function activateOptions() { } |
|
| 65 | + /** |
|
| 66 | + * Called in constructor. Converters which need to process the options |
|
| 67 | + * can override this method. |
|
| 68 | + */ |
|
| 69 | + public function activateOptions() { } |
|
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * Converts the logging event to the desired format. Derived pattern |
|
| 73 | - * converters must implement this method. |
|
| 74 | - * |
|
| 75 | - * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 76 | - */ |
|
| 77 | - abstract public function convert(Payone_Log4php_LoggerLoggingEvent $event); |
|
| 71 | + /** |
|
| 72 | + * Converts the logging event to the desired format. Derived pattern |
|
| 73 | + * converters must implement this method. |
|
| 74 | + * |
|
| 75 | + * @param Payone_Log4php_LoggerLoggingEvent $event |
|
| 76 | + */ |
|
| 77 | + abstract public function convert(Payone_Log4php_LoggerLoggingEvent $event); |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Converts the event and formats it according to setting in the |
|
| 81 | - * Formatting information object. |
|
| 82 | - * |
|
| 83 | - * @param string &$sbuf string buffer to write to |
|
| 84 | - * @param Payone_Log4php_LoggerLoggingEvent $event Event to be formatted. |
|
| 85 | - */ |
|
| 86 | - public function format(&$sbuf, $event) { |
|
| 87 | - $string = $this->convert($event); |
|
| 79 | + /** |
|
| 80 | + * Converts the event and formats it according to setting in the |
|
| 81 | + * Formatting information object. |
|
| 82 | + * |
|
| 83 | + * @param string &$sbuf string buffer to write to |
|
| 84 | + * @param Payone_Log4php_LoggerLoggingEvent $event Event to be formatted. |
|
| 85 | + */ |
|
| 86 | + public function format(&$sbuf, $event) { |
|
| 87 | + $string = $this->convert($event); |
|
| 88 | 88 | |
| 89 | - if (!isset($this->formattingInfo)) { |
|
| 90 | - $sbuf .= $string; |
|
| 91 | - return; |
|
| 92 | - } |
|
| 89 | + if (!isset($this->formattingInfo)) { |
|
| 90 | + $sbuf .= $string; |
|
| 91 | + return; |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - $fi = $this->formattingInfo; |
|
| 94 | + $fi = $this->formattingInfo; |
|
| 95 | 95 | |
| 96 | - // Empty string |
|
| 97 | - if($string === '' || is_null($string)) { |
|
| 98 | - if($fi->min > 0) { |
|
| 99 | - $sbuf .= str_repeat(' ', $fi->min); |
|
| 100 | - } |
|
| 101 | - return; |
|
| 102 | - } |
|
| 96 | + // Empty string |
|
| 97 | + if($string === '' || is_null($string)) { |
|
| 98 | + if($fi->min > 0) { |
|
| 99 | + $sbuf .= str_repeat(' ', $fi->min); |
|
| 100 | + } |
|
| 101 | + return; |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - $len = strlen($string); |
|
| 104 | + $len = strlen($string); |
|
| 105 | 105 | |
| 106 | - // Trim the string if needed |
|
| 107 | - if($len > $fi->max) { |
|
| 108 | - if ($fi->trimLeft) { |
|
| 109 | - $sbuf .= substr($string, $len - $fi->max, $fi->max); |
|
| 110 | - } else { |
|
| 111 | - $sbuf .= substr($string , 0, $fi->max); |
|
| 112 | - } |
|
| 113 | - } |
|
| 106 | + // Trim the string if needed |
|
| 107 | + if($len > $fi->max) { |
|
| 108 | + if ($fi->trimLeft) { |
|
| 109 | + $sbuf .= substr($string, $len - $fi->max, $fi->max); |
|
| 110 | + } else { |
|
| 111 | + $sbuf .= substr($string , 0, $fi->max); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - // Add padding if needed |
|
| 116 | - else if($len < $fi->min) { |
|
| 117 | - if($fi->padLeft) { |
|
| 118 | - $sbuf .= str_repeat(' ', $fi->min - $len); |
|
| 119 | - $sbuf .= $string; |
|
| 120 | - } else { |
|
| 121 | - $sbuf .= $string; |
|
| 122 | - $sbuf .= str_repeat(' ', $fi->min - $len); |
|
| 123 | - } |
|
| 124 | - } |
|
| 115 | + // Add padding if needed |
|
| 116 | + else if($len < $fi->min) { |
|
| 117 | + if($fi->padLeft) { |
|
| 118 | + $sbuf .= str_repeat(' ', $fi->min - $len); |
|
| 119 | + $sbuf .= $string; |
|
| 120 | + } else { |
|
| 121 | + $sbuf .= $string; |
|
| 122 | + $sbuf .= str_repeat(' ', $fi->min - $len); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - // No action needed |
|
| 127 | - else { |
|
| 128 | - $sbuf .= $string; |
|
| 129 | - } |
|
| 130 | - } |
|
| 126 | + // No action needed |
|
| 127 | + else { |
|
| 128 | + $sbuf .= $string; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | 131 | } |
@@ -94,8 +94,8 @@ discard block |
||
| 94 | 94 | $fi = $this->formattingInfo; |
| 95 | 95 | |
| 96 | 96 | // Empty string |
| 97 | - if($string === '' || is_null($string)) { |
|
| 98 | - if($fi->min > 0) { |
|
| 97 | + if ($string === '' || is_null($string)) { |
|
| 98 | + if ($fi->min > 0) { |
|
| 99 | 99 | $sbuf .= str_repeat(' ', $fi->min); |
| 100 | 100 | } |
| 101 | 101 | return; |
@@ -104,17 +104,17 @@ discard block |
||
| 104 | 104 | $len = strlen($string); |
| 105 | 105 | |
| 106 | 106 | // Trim the string if needed |
| 107 | - if($len > $fi->max) { |
|
| 107 | + if ($len > $fi->max) { |
|
| 108 | 108 | if ($fi->trimLeft) { |
| 109 | 109 | $sbuf .= substr($string, $len - $fi->max, $fi->max); |
| 110 | 110 | } else { |
| 111 | - $sbuf .= substr($string , 0, $fi->max); |
|
| 111 | + $sbuf .= substr($string, 0, $fi->max); |
|
| 112 | 112 | } |
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | // Add padding if needed |
| 116 | - else if($len < $fi->min) { |
|
| 117 | - if($fi->padLeft) { |
|
| 116 | + else if ($len < $fi->min) { |
|
| 117 | + if ($fi->padLeft) { |
|
| 118 | 118 | $sbuf .= str_repeat(' ', $fi->min - $len); |
| 119 | 119 | $sbuf .= $string; |
| 120 | 120 | } else { |
@@ -64,6 +64,8 @@ |
||
| 64 | 64 | /** |
| 65 | 65 | * Attempts to shorten the given name to the desired length by trimming |
| 66 | 66 | * name fragments. See docs for examples. |
| 67 | + * @param string $name |
|
| 68 | + * @param integer $length |
|
| 67 | 69 | */ |
| 68 | 70 | private function shorten($name, $length) { |
| 69 | 71 | |
@@ -29,86 +29,86 @@ |
||
| 29 | 29 | */ |
| 30 | 30 | class Payone_Log4php_LoggerPatternConverterLogger extends Payone_Log4php_LoggerPatternConverter { |
| 31 | 31 | |
| 32 | - /** Length to which to shorten the name. */ |
|
| 33 | - private $length; |
|
| 32 | + /** Length to which to shorten the name. */ |
|
| 33 | + private $length; |
|
| 34 | 34 | |
| 35 | - /** Holds processed logger names. */ |
|
| 36 | - private $cache = array(); |
|
| 35 | + /** Holds processed logger names. */ |
|
| 36 | + private $cache = array(); |
|
| 37 | 37 | |
| 38 | - public function activateOptions() { |
|
| 39 | - // Parse the option (desired output length) |
|
| 40 | - if (isset($this->option) && is_numeric($this->option) && $this->option >= 0) { |
|
| 41 | - $this->length = (integer) $this->option; |
|
| 42 | - } |
|
| 43 | - } |
|
| 38 | + public function activateOptions() { |
|
| 39 | + // Parse the option (desired output length) |
|
| 40 | + if (isset($this->option) && is_numeric($this->option) && $this->option >= 0) { |
|
| 41 | + $this->length = (integer) $this->option; |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 46 | - $name = $event->getLoggerName(); |
|
| 45 | + public function convert(Payone_Log4php_LoggerLoggingEvent $event) { |
|
| 46 | + $name = $event->getLoggerName(); |
|
| 47 | 47 | |
| 48 | - if (!isset($this->cache[$name])) { |
|
| 48 | + if (!isset($this->cache[$name])) { |
|
| 49 | 49 | |
| 50 | - // If length is set return shortened logger name |
|
| 51 | - if (isset($this->length)) { |
|
| 52 | - $this->cache[$name] = $this->shorten($name, $this->length); |
|
| 53 | - } |
|
| 50 | + // If length is set return shortened logger name |
|
| 51 | + if (isset($this->length)) { |
|
| 52 | + $this->cache[$name] = $this->shorten($name, $this->length); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - // If no length is specified return full logger name |
|
| 56 | - else { |
|
| 57 | - $this->cache[$name] = $name; |
|
| 58 | - } |
|
| 59 | - } |
|
| 55 | + // If no length is specified return full logger name |
|
| 56 | + else { |
|
| 57 | + $this->cache[$name] = $name; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - return $this->cache[$name]; |
|
| 62 | - } |
|
| 61 | + return $this->cache[$name]; |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * Attempts to shorten the given name to the desired length by trimming |
|
| 66 | - * name fragments. See docs for examples. |
|
| 67 | - */ |
|
| 68 | - private function shorten($name, $length) { |
|
| 64 | + /** |
|
| 65 | + * Attempts to shorten the given name to the desired length by trimming |
|
| 66 | + * name fragments. See docs for examples. |
|
| 67 | + */ |
|
| 68 | + private function shorten($name, $length) { |
|
| 69 | 69 | |
| 70 | - $currentLength = strlen($name); |
|
| 70 | + $currentLength = strlen($name); |
|
| 71 | 71 | |
| 72 | - // Check if any shortening is required |
|
| 73 | - if ($currentLength <= $length) { |
|
| 74 | - return $name; |
|
| 75 | - } |
|
| 72 | + // Check if any shortening is required |
|
| 73 | + if ($currentLength <= $length) { |
|
| 74 | + return $name; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - // Split name into fragments |
|
| 78 | - $name = str_replace('.', '\\', $name); |
|
| 79 | - $name = trim($name, ' \\'); |
|
| 80 | - $fragments = explode('\\', $name); |
|
| 81 | - $count = count($fragments); |
|
| 77 | + // Split name into fragments |
|
| 78 | + $name = str_replace('.', '\\', $name); |
|
| 79 | + $name = trim($name, ' \\'); |
|
| 80 | + $fragments = explode('\\', $name); |
|
| 81 | + $count = count($fragments); |
|
| 82 | 82 | |
| 83 | - // If the name splits to only one fragment, then it cannot be shortened |
|
| 84 | - if ($count == 1) { |
|
| 85 | - return $name; |
|
| 86 | - } |
|
| 83 | + // If the name splits to only one fragment, then it cannot be shortened |
|
| 84 | + if ($count == 1) { |
|
| 85 | + return $name; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - foreach($fragments as $key => &$fragment) { |
|
| 88 | + foreach($fragments as $key => &$fragment) { |
|
| 89 | 89 | |
| 90 | - // Never shorten last fragment |
|
| 91 | - if ($key == $count - 1) { |
|
| 92 | - break; |
|
| 93 | - } |
|
| 90 | + // Never shorten last fragment |
|
| 91 | + if ($key == $count - 1) { |
|
| 92 | + break; |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - // Check for empty fragments (shouldn't happen but it's possible) |
|
| 96 | - $fragLen = strlen($fragment); |
|
| 97 | - if ($fragLen <= 1) { |
|
| 98 | - continue; |
|
| 99 | - } |
|
| 95 | + // Check for empty fragments (shouldn't happen but it's possible) |
|
| 96 | + $fragLen = strlen($fragment); |
|
| 97 | + if ($fragLen <= 1) { |
|
| 98 | + continue; |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - // Shorten fragment to one character and check if total length satisfactory |
|
| 102 | - $fragment = substr($fragment, 0, 1); |
|
| 103 | - $currentLength = $currentLength - $fragLen + 1; |
|
| 101 | + // Shorten fragment to one character and check if total length satisfactory |
|
| 102 | + $fragment = substr($fragment, 0, 1); |
|
| 103 | + $currentLength = $currentLength - $fragLen + 1; |
|
| 104 | 104 | |
| 105 | - if ($currentLength <= $length) { |
|
| 106 | - break; |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - unset($fragment); |
|
| 105 | + if ($currentLength <= $length) { |
|
| 106 | + break; |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + unset($fragment); |
|
| 110 | 110 | |
| 111 | - return implode('\\', $fragments); |
|
| 112 | - } |
|
| 111 | + return implode('\\', $fragments); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | public function activateOptions() { |
| 39 | 39 | // Parse the option (desired output length) |
| 40 | 40 | if (isset($this->option) && is_numeric($this->option) && $this->option >= 0) { |
| 41 | - $this->length = (integer) $this->option; |
|
| 41 | + $this->length = (integer)$this->option; |
|
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | return $name; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - foreach($fragments as $key => &$fragment) { |
|
| 88 | + foreach ($fragments as $key => &$fragment) { |
|
| 89 | 89 | |
| 90 | 90 | // Never shorten last fragment |
| 91 | 91 | if ($key == $count - 1) { |
@@ -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 | } |
@@ -34,7 +34,7 @@ |
||
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | - * @param $key |
|
| 37 | + * @param string $key |
|
| 38 | 38 | * @return Payone_Settings_Service_XmlGenerate |
| 39 | 39 | * |
| 40 | 40 | * @throws Exception |
@@ -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) |