| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
namespace JFB_Modules\Logger; |
| 5 |
|
| 6 |
use JFB_Components\Module\Base_Module_It; |
| 7 |
use JFB_Components\Module\Base_Module_Static_Instance_It; |
| 8 |
use JFB_Components\Module\Base_Module_Static_Instance_Trait; |
| 9 |
|
| 10 |
// If this file is called directly, abort. |
| 11 |
if ( ! defined( 'WPINC' ) ) { |
| 12 |
die; |
| 13 |
} |
| 14 |
|
| 15 |
/** |
| 16 |
* @method static Module instance() |
| 17 |
* |
| 18 |
* Class Logger |
| 19 |
* @package Jet_Form_Builder\Dev_Mode |
| 20 |
*/ |
| 21 |
final class Module implements Base_Module_It, Base_Module_Static_Instance_It { |
| 22 |
|
| 23 |
use Base_Module_Static_Instance_Trait; |
| 24 |
|
| 25 |
private $logged = array(); |
| 26 |
|
| 27 |
public static function get_instance_id(): string { |
| 28 |
return 'logger'; |
| 29 |
} |
| 30 |
|
| 31 |
public function condition(): bool { |
| 32 |
return true; |
| 33 |
} |
| 34 |
|
| 35 |
public function init_hooks() { |
| 36 |
} |
| 37 |
|
| 38 |
public function remove_hooks() { |
| 39 |
} |
| 40 |
|
| 41 |
public function get_logs(): array { |
| 42 |
return $this->logged; |
| 43 |
} |
| 44 |
|
| 45 |
public function push_log( string $name, $data ) { |
| 46 |
if ( ! array_key_exists( $name, $this->logged ) ) { |
| 47 |
$this->logged[ $name ] = array(); |
| 48 |
} |
| 49 |
|
| 50 |
$this->logged[ $name ][] = $data; |
| 51 |
} |
| 52 |
|
| 53 |
public function unset_last( string $key ) { |
| 54 |
$exceptions = $this->logged[ $key ] ?? array(); |
| 55 |
|
| 56 |
if ( ! count( $exceptions ) ) { |
| 57 |
return; |
| 58 |
} |
| 59 |
|
| 60 |
array_pop( $this->logged[ $key ] ); |
| 61 |
} |
| 62 |
|
| 63 |
|
| 64 |
/** |
| 65 |
* @since 3.1.0 |
| 66 |
* |
| 67 |
* @param string $slug |
| 68 |
* |
| 69 |
* @return bool |
| 70 |
*/ |
| 71 |
public function has_log( string $slug ): bool { |
| 72 |
foreach ( $this->logged as $exception_name => $args ) { |
| 73 |
if ( $slug === $exception_name ) { |
| 74 |
return true; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
return false; |
| 79 |
} |
| 80 |
} |
| 81 |
|