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