# decalog/4.4.0/includes/plugin/class-initializer.php

DecaLog, version 4.4.0. 85 lines.

- Page: https://pluginprobe.com/plugins/decalog/4.4.0/code/includes/plugin/class-initializer.php
- Raw: https://pluginprobe.com/plugins/decalog/4.4.0/raw/includes/plugin/class-initializer.php
- Modified: 2024-11-22T18:27:42+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/decalog/4.4.0/code/includes/plugin/class-initializer.php#L10-L20`.

```php
<?php
/**
 * Plugin initialization handling.
 *
 * @package Plugin
 * @author  Pierre Lannoy <https://pierre.lannoy.fr/>.
 * @since   1.0.0
 */

namespace Decalog\Plugin;

use Decalog\Plugin\Feature\Log;

/**
 * Fired after 'init' hook.
 *
 * This class defines all code necessary to run during the plugin's initialization.
 *
 * @package Plugin
 * @author  Pierre Lannoy <https://pierre.lannoy.fr/>.
 * @since   1.0.0
 */
class Initializer {

	/**
	 * Initialize the class and set its properties.
	 *
	 * @since   1.0.0
	 */
	public function __construct() {

	}

	/**
	 * Initialize the plugin.
	 *
	 * @since 1.0.0
	 */
	public function initialize() {
		\Decalog\System\Cache::init();
		\Decalog\System\Sitehealth::init();
		\Decalog\System\APCu::init();
	}

	/**
	 * Late initialize the plugin.
	 *
	 * @since 1.0.0
	 */
	public function late_initialize() {
		require_once DECALOG_PLUGIN_DIR . 'perfopsone/init.php';
		$this->wpcli_initialize();
	}

	/**
	 * Initialize the plugin in wp-cli mode.
	 *
	 * @since 3.6.0
	 */
	public function wpcli_initialize() {
		if ( defined( 'WP_CLI' ) && WP_CLI ) {
			if ( method_exists( '\WP_CLI', 'set_logger') && method_exists( '\WP_CLI', 'get_logger') ) {
				$class = str_replace( 'WP_CLI\Loggers\\', 'Decalog\Listener\WP_CLI\\', get_class( \WP_CLI::get_logger() ) );
				if ( class_exists( $class ) ) {
					try {
						$reflection = new \ReflectionClass( $class );
						$instance   = $reflection->newInstance();
						\WP_CLI::set_logger( $instance );
					} catch ( \Exception $e ) {
						$logger = Log::bootstrap( 'plugin', DECALOG_PRODUCT_SHORTNAME, DECALOG_VERSION );
						$logger->critical( sprintf( 'Unable to instanciate `%s` class. DecaLog will not log following WP-CLI events.', $class ) );
					}
				} else {
					$logger = Log::bootstrap( 'plugin', DECALOG_PRODUCT_SHORTNAME, DECALOG_VERSION );
					$logger->critical( sprintf( 'Unable to find `%s` class. DecaLog will not log following WP-CLI events.', $class ) );
				}
			} else {
				$logger = Log::bootstrap( 'plugin', DECALOG_PRODUCT_SHORTNAME, DECALOG_VERSION );
				$logger->warning( 'WP-CLI is outdated: DecaLog will not be able to report events triggered in interactive command-line session. Please, update WP-CLI!' );
			}
		}
	}

}

```
