| 1 |
<?php |
| 2 |
/** |
| 3 |
* Event types handling |
| 4 |
* |
| 5 |
* Handles all available event types. |
| 6 |
* |
| 7 |
* @package Features |
| 8 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 9 |
* @since 1.0.0 |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace Decalog\Plugin\Feature; |
| 13 |
|
| 14 |
use DLMonolog\Logger; |
| 15 |
use Feather; |
| 16 |
|
| 17 |
/** |
| 18 |
* Define the event types functionality. |
| 19 |
* |
| 20 |
* Handles all available event types. |
| 21 |
* |
| 22 |
* @package Features |
| 23 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 24 |
* @since 1.0.0 |
| 25 |
*/ |
| 26 |
class EventTypes { |
| 27 |
|
| 28 |
/** |
| 29 |
* List of the available levels. |
| 30 |
* |
| 31 |
* @since 1.0.0 |
| 32 |
* @var string[] $levels Logging levels. |
| 33 |
*/ |
| 34 |
public static $levels = [ |
| 35 |
'debug' => Logger::DEBUG, |
| 36 |
'info' => Logger::INFO, |
| 37 |
'notice' => Logger::NOTICE, |
| 38 |
'warning' => Logger::WARNING, |
| 39 |
'error' => Logger::ERROR, |
| 40 |
'critical' => Logger::CRITICAL, |
| 41 |
'alert' => Logger::ALERT, |
| 42 |
'emergency' => Logger::EMERGENCY, |
| 43 |
]; |
| 44 |
|
| 45 |
/** |
| 46 |
* List of the levels colors. |
| 47 |
* |
| 48 |
* @since 3.0.0 |
| 49 |
* @var string[] $levels_colors Logging levels colors. |
| 50 |
*/ |
| 51 |
public static $levels_colors = [ |
| 52 |
'unknown' => [ '#F0F0F0', '#CCCCCC' ], |
| 53 |
'debug' => [ '#F0F0F0', '#CCCCCC' ], |
| 54 |
'info' => [ '#EEEEFF', '#9999FF' ], |
| 55 |
'notice' => [ '#DDDDFF', '#5555FF' ], |
| 56 |
'warning' => [ '#FFFFC4', '#FFAB10' ], |
| 57 |
'error' => [ '#FFD2A8', '#FB7B00' ], |
| 58 |
'critical' => [ '#FFB7B7', '#FF0000' ], |
| 59 |
'alert' => [ '#FFB7B7', '#DD0000' ], |
| 60 |
'emergency' => [ '#FFB7B7', '#AA0000' ], |
| 61 |
]; |
| 62 |
|
| 63 |
/** |
| 64 |
* List of the available WSAL levels. |
| 65 |
* |
| 66 |
* @since 1.0.0 |
| 67 |
* @var string[] $levels Logging levels. |
| 68 |
*/ |
| 69 |
public static $wsal_levels = [ |
| 70 |
7 => Logger::DEBUG, |
| 71 |
6 => Logger::INFO, |
| 72 |
5 => Logger::NOTICE, |
| 73 |
4 => Logger::WARNING, |
| 74 |
3 => Logger::ERROR, |
| 75 |
2 => Logger::CRITICAL, |
| 76 |
1 => Logger::ALERT, |
| 77 |
0 => Logger::EMERGENCY, |
| 78 |
]; |
| 79 |
|
| 80 |
/** |
| 81 |
* List of the available icons. |
| 82 |
* |
| 83 |
* @since 1.0.0 |
| 84 |
* @var string[] $icons Logging levels. |
| 85 |
*/ |
| 86 |
public static $icons = []; |
| 87 |
|
| 88 |
/** |
| 89 |
* List of the available level texts. |
| 90 |
* |
| 91 |
* @var string[] $level_texts Logging levels texts. |
| 92 |
*/ |
| 93 |
public static $level_texts = []; |
| 94 |
|
| 95 |
/** |
| 96 |
* List of the available level names. |
| 97 |
* |
| 98 |
* @var string[] $level_names Logging levels names. |
| 99 |
*/ |
| 100 |
public static $level_names = [ |
| 101 |
Logger::DEBUG => 'DEBUG', |
| 102 |
Logger::INFO => 'INFO', |
| 103 |
Logger::NOTICE => 'NOTICE', |
| 104 |
Logger::WARNING => 'WARNING', |
| 105 |
Logger::ERROR => 'ERROR', |
| 106 |
Logger::CRITICAL => 'CRITICAL', |
| 107 |
Logger::ALERT => 'ALERT', |
| 108 |
Logger::EMERGENCY => 'EMERGENCY', |
| 109 |
]; |
| 110 |
|
| 111 |
/** |
| 112 |
* List of the available Loki level names. |
| 113 |
* |
| 114 |
* @var string[] $loki_level_names Logging levels names. |
| 115 |
*/ |
| 116 |
public static $loki_level_names = [ |
| 117 |
Logger::DEBUG => 'DEBUG', |
| 118 |
Logger::INFO => 'INFO', |
| 119 |
Logger::NOTICE => 'INFO', |
| 120 |
Logger::WARNING => 'WARNING', |
| 121 |
Logger::ERROR => 'ERROR', |
| 122 |
Logger::CRITICAL => 'ERROR', |
| 123 |
Logger::ALERT => 'FATAL', |
| 124 |
Logger::EMERGENCY => 'FATAL', |
| 125 |
]; |
| 126 |
|
| 127 |
/** |
| 128 |
* List of the available level emojis. |
| 129 |
* |
| 130 |
* @var string[] $level_names Logging levels emojis. |
| 131 |
*/ |
| 132 |
public static $level_emojis = [ |
| 133 |
Logger::DEBUG => '⬜', |
| 134 |
Logger::INFO => '🟦', |
| 135 |
Logger::NOTICE => '🟩', |
| 136 |
Logger::WARNING => '🟨', |
| 137 |
Logger::ERROR => '🟧', |
| 138 |
Logger::CRITICAL => '🟥', |
| 139 |
Logger::ALERT => '🟪', |
| 140 |
Logger::EMERGENCY => '⬛', |
| 141 |
]; |
| 142 |
|
| 143 |
/** |
| 144 |
* List of the available levels. |
| 145 |
* |
| 146 |
* @since 1.0.0 |
| 147 |
* @var string[] $level_values Logging levels. |
| 148 |
*/ |
| 149 |
public static $level_values = [ |
| 150 |
Logger::DEBUG, |
| 151 |
Logger::INFO, |
| 152 |
Logger::NOTICE, |
| 153 |
Logger::WARNING, |
| 154 |
Logger::ERROR, |
| 155 |
Logger::CRITICAL, |
| 156 |
Logger::ALERT, |
| 157 |
Logger::EMERGENCY, |
| 158 |
]; |
| 159 |
|
| 160 |
/** |
| 161 |
* Initialize the meta class and set its properties. |
| 162 |
* |
| 163 |
* @since 1.0.0 |
| 164 |
*/ |
| 165 |
public static function init() { |
| 166 |
self::$icons = []; |
| 167 |
self::$icons['unknown'] = Feather\Icons::get_base64( 'circle', '#F0F0F0', '#CCCCCC' ); |
| 168 |
self::$icons['debug'] = Feather\Icons::get_base64( 'info', '#F0F0F0', '#CCCCCC' ); |
| 169 |
self::$icons['info'] = Feather\Icons::get_base64( 'info', '#EEEEFF', '#9999FF' ); |
| 170 |
self::$icons['notice'] = Feather\Icons::get_base64( 'info', '#DDDDFF', '#5555FF' ); |
| 171 |
self::$icons['warning'] = Feather\Icons::get_base64( 'alert-circle', '#FFFFC4', '#FFAB10' ); |
| 172 |
self::$icons['error'] = Feather\Icons::get_base64( 'alert-circle', '#FFD2A8', '#FB7B00' ); |
| 173 |
self::$icons['critical'] = Feather\Icons::get_base64( 'alert-circle', '#FFB7B7', '#FF0000' ); |
| 174 |
self::$icons['alert'] = Feather\Icons::get_base64( 'x-circle', '#FFB7B7', '#DD0000' ); |
| 175 |
self::$icons['emergency'] = Feather\Icons::get_base64( 'x-circle', '#FFB7B7', '#AA0000' ); |
| 176 |
self::$level_texts = []; |
| 177 |
/* translators: definition of an event typed 'UNKNOWN' */ |
| 178 |
self::$level_texts['unknown'] = decalog_esc_html__( 'The event is not typed, this can\'t be a good news.', 'decalog' ); |
| 179 |
/* translators: definition of an event typed 'DEBUG', see https://github.com/Pierre-Lannoy/wp-decalog/blob/master/DEVELOPER.md for details*/ |
| 180 |
self::$level_texts['debug'] = decalog_esc_html__( 'An information for developers and testers. Only used for events related to application/system debugging.', 'decalog' ); |
| 181 |
/* translators: definition of an event typed 'INFO', see https://github.com/Pierre-Lannoy/wp-decalog/blob/master/DEVELOPER.md for details*/ |
| 182 |
self::$level_texts['info'] = decalog_esc_html__( 'A standard information, just for you to know… and forget!', 'decalog' ); |
| 183 |
/* translators: definition of an event typed 'NOTICE', see https://github.com/Pierre-Lannoy/wp-decalog/blob/master/DEVELOPER.md for details*/ |
| 184 |
self::$level_texts['notice'] = decalog_esc_html__( 'A normal but significant condition. Now you know!', 'decalog' ); |
| 185 |
/* translators: definition of an event typed 'WARNING', see https://github.com/Pierre-Lannoy/wp-decalog/blob/master/DEVELOPER.md for details*/ |
| 186 |
self::$level_texts['warning'] = decalog_esc_html__( 'A significant condition indicating a situation that may lead to an error if recurring or if no action is taken. Does not usually affect the operations.', 'decalog' ); |
| 187 |
/* translators: definition of an event typed 'ERROR', see https://github.com/Pierre-Lannoy/wp-decalog/blob/master/DEVELOPER.md for details*/ |
| 188 |
self::$level_texts['error'] = decalog_esc_html__( 'A minor operating error that may affects the operations. It requires investigation and preventive treatment.', 'decalog' ); |
| 189 |
/* translators: definition of an event typed 'CRITICAL', see https://github.com/Pierre-Lannoy/wp-decalog/blob/master/DEVELOPER.md for details*/ |
| 190 |
self::$level_texts['critical'] = decalog_esc_html__( 'An operating error that undoubtedly affects the operations. It requires investigation and corrective treatment.', 'decalog' ); |
| 191 |
/* translators: definition of an event typed 'ALERT', see https://github.com/Pierre-Lannoy/wp-decalog/blob/master/DEVELOPER.md for details*/ |
| 192 |
self::$level_texts['alert'] = decalog_esc_html__( 'A major operating error that undoubtedly affects the operations. It requires immediate investigation and corrective treatment.', 'decalog' ); |
| 193 |
/* translators: definition of an event typed 'EMERGENCY', see https://github.com/Pierre-Lannoy/wp-decalog/blob/master/DEVELOPER.md for details*/ |
| 194 |
self::$level_texts['emergency'] = decalog_esc_html__( 'A panic condition. WordPress is unusable.', 'decalog' ); |
| 195 |
} |
| 196 |
|
| 197 |
/** |
| 198 |
* Get a standardized level. |
| 199 |
* |
| 200 |
* @return integer The standardized level. |
| 201 |
* @since 1.14.0 |
| 202 |
*/ |
| 203 |
public static function get_standard_level( $level ) { |
| 204 |
if ( is_string( $level ) ) { |
| 205 |
if ( array_key_exists( strtolower( $level ), self::$levels ) ) { |
| 206 |
return self::$levels[ strtolower( $level ) ]; |
| 207 |
} else { |
| 208 |
return 0; |
| 209 |
} |
| 210 |
} |
| 211 |
if ( is_int( $level ) ) { |
| 212 |
return 0; |
| 213 |
} |
| 214 |
} |
| 215 |
|
| 216 |
} |
| 217 |
|
| 218 |
EventTypes::init(); |
| 219 |
|