Console.php
87 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * ====================================================================== |
| 5 | * LICENSE: This file is subject to the terms and conditions defined in * |
| 6 | * file 'license.txt', which is part of this source code package. * |
| 7 | * ====================================================================== |
| 8 | */ |
| 9 | |
| 10 | /** |
| 11 | * AAM Core notification consol |
| 12 | * |
| 13 | * Track and display list of all warnings that has been detected during AAM |
| 14 | * execution. The consol is used only when AAM interface was triggered in Admin side. |
| 15 | * |
| 16 | * @package AAM |
| 17 | * @version 7.0.0 |
| 18 | */ |
| 19 | class AAM_Core_Console |
| 20 | { |
| 21 | |
| 22 | /** |
| 23 | * List of Runtime errors related to AAM |
| 24 | * |
| 25 | * @var array |
| 26 | * @access private |
| 27 | * |
| 28 | * @version 7.0.0 |
| 29 | */ |
| 30 | private static $_messages = array(); |
| 31 | |
| 32 | /** |
| 33 | * Add new warning |
| 34 | * |
| 35 | * @param string $message |
| 36 | * @param string $args... |
| 37 | * |
| 38 | * @return void |
| 39 | * @access public |
| 40 | * |
| 41 | * @version 7.0.0 |
| 42 | */ |
| 43 | public static function add($message) |
| 44 | { |
| 45 | //prepare search patterns |
| 46 | $num = func_num_args(); |
| 47 | $search = ($num > 1 ? array_fill(0, ($num - 1) * 2, null) : []); |
| 48 | |
| 49 | array_walk($search, function (&$value, $index) { |
| 50 | $value = '/\\' . ($index % 2 ? ']' : '[') . '/'; |
| 51 | }); |
| 52 | |
| 53 | $replace = array(); |
| 54 | foreach (array_slice(func_get_args(), 1) as $key) { |
| 55 | array_push($replace, "<{$key}>", "</{$key}>"); |
| 56 | } |
| 57 | |
| 58 | self::$_messages[] = preg_replace($search, $replace, $message, 1); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Get list of all warnings |
| 63 | * |
| 64 | * @return array |
| 65 | * @access public |
| 66 | * |
| 67 | * @version 7.0.0 |
| 68 | */ |
| 69 | public static function get_all() |
| 70 | { |
| 71 | return self::$_messages; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Count the list of all notifications |
| 76 | * |
| 77 | * @return int |
| 78 | * @access public |
| 79 | * |
| 80 | * @version 7.0.0 |
| 81 | */ |
| 82 | public static function count() |
| 83 | { |
| 84 | return count(self::$_messages); |
| 85 | } |
| 86 | |
| 87 | } |