| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plugin initialization handling. |
| 4 |
* |
| 5 |
* @package Plugin |
| 6 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 7 |
* @since 1.0.0 |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace Decalog\Plugin; |
| 11 |
|
| 12 |
use Decalog\Plugin\Feature\Log; |
| 13 |
|
| 14 |
/** |
| 15 |
* Fired after 'init' hook. |
| 16 |
* |
| 17 |
* This class defines all code necessary to run during the plugin's initialization. |
| 18 |
* |
| 19 |
* @package Plugin |
| 20 |
* @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
| 21 |
* @since 1.0.0 |
| 22 |
*/ |
| 23 |
class Initializer { |
| 24 |
|
| 25 |
/** |
| 26 |
* Initialize the class and set its properties. |
| 27 |
* |
| 28 |
* @since 1.0.0 |
| 29 |
*/ |
| 30 |
public function __construct() { |
| 31 |
|
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Initialize the plugin. |
| 36 |
* |
| 37 |
* @since 1.0.0 |
| 38 |
*/ |
| 39 |
public function initialize() { |
| 40 |
\Decalog\System\Cache::init(); |
| 41 |
\Decalog\System\Sitehealth::init(); |
| 42 |
\Decalog\System\APCu::init(); |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Late initialize the plugin. |
| 47 |
* |
| 48 |
* @since 1.0.0 |
| 49 |
*/ |
| 50 |
public function late_initialize() { |
| 51 |
require_once DECALOG_PLUGIN_DIR . 'perfopsone/init.php'; |
| 52 |
$this->wpcli_initialize(); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Initialize the plugin in wp-cli mode. |
| 57 |
* |
| 58 |
* @since 3.6.0 |
| 59 |
*/ |
| 60 |
public function wpcli_initialize() { |
| 61 |
if ( defined( 'WP_CLI' ) && WP_CLI ) { |
| 62 |
if ( method_exists( '\WP_CLI', 'set_logger') && method_exists( '\WP_CLI', 'get_logger') ) { |
| 63 |
$class = str_replace( 'WP_CLI\Loggers\\', 'Decalog\Listener\WP_CLI\\', get_class( \WP_CLI::get_logger() ) ); |
| 64 |
if ( class_exists( $class ) ) { |
| 65 |
try { |
| 66 |
$reflection = new \ReflectionClass( $class ); |
| 67 |
$instance = $reflection->newInstance(); |
| 68 |
\WP_CLI::set_logger( $instance ); |
| 69 |
} catch ( \Exception $e ) { |
| 70 |
$logger = Log::bootstrap( 'plugin', DECALOG_PRODUCT_SHORTNAME, DECALOG_VERSION ); |
| 71 |
$logger->critical( sprintf( 'Unable to instanciate `%s` class. DecaLog will not log following WP-CLI events.', $class ) ); |
| 72 |
} |
| 73 |
} else { |
| 74 |
$logger = Log::bootstrap( 'plugin', DECALOG_PRODUCT_SHORTNAME, DECALOG_VERSION ); |
| 75 |
$logger->critical( sprintf( 'Unable to find `%s` class. DecaLog will not log following WP-CLI events.', $class ) ); |
| 76 |
} |
| 77 |
} else { |
| 78 |
$logger = Log::bootstrap( 'plugin', DECALOG_PRODUCT_SHORTNAME, DECALOG_VERSION ); |
| 79 |
$logger->warning( 'WP-CLI is outdated: DecaLog will not be able to report events triggered in interactive command-line session. Please, update WP-CLI!' ); |
| 80 |
} |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
} |
| 85 |
|