From: scribu Date: Tue, 2 Jul 2013 15:22:41 +0000 (+0200) Subject: instantiate WP_CLI\Runner on demand; see #571 X-Git-Tag: v0.11.0~55 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=eaac711c6f3e204c5a59da09ab97e60497c99204;p=wvm%2Fwvm.git instantiate WP_CLI\Runner on demand; see #571 This allows early commands to be defined in third-party packages. --- diff --git a/php/class-wp-cli.php b/php/class-wp-cli.php index 9b91d35f..784a2962 100644 --- a/php/class-wp-cli.php +++ b/php/class-wp-cli.php @@ -9,7 +9,6 @@ use \WP_CLI\Dispatcher; class WP_CLI { private static $configurator; - public static $runner; private static $logger; @@ -24,7 +23,6 @@ class WP_CLI { self::add_man_dir( null, WP_CLI_ROOT . "/man-src" ); self::$configurator = new WP_CLI\Configurator( WP_CLI_ROOT . '/php/config-spec.php' ); - self::$runner = new WP_CLI\Runner; } /** @@ -40,12 +38,28 @@ class WP_CLI { return self::$configurator; } + static function get_root_command() { + static $root; + + if ( !$root ) { + $root = new Dispatcher\RootCommand; + } + + return $root; + } + static function get_runner() { - return self::$runner; + static $runner; + + if ( !$runner ) { + $runner = new WP_CLI\Runner; + } + + return $runner; } static function colorize( $string ) { - return \cli\Colors::colorize( $string, self::$runner->in_color() ); + return \cli\Colors::colorize( $string, self::get_runner()->in_color() ); } /** @@ -88,16 +102,6 @@ class WP_CLI { self::get_root_command()->add_subcommand( $name, $command ); } - static function get_root_command() { - static $root; - - if ( !$root ) { - $root = new Dispatcher\RootCommand; - } - - return $root; - } - static function add_man_dir( $deprecated = null, $src_dir ) { self::$man_dirs[] = $src_dir; } @@ -151,7 +155,7 @@ class WP_CLI { * @param string $label */ static function error( $message, $label = 'Error' ) { - if ( ! isset( self::$runner->assoc_args[ 'completions' ] ) ) { + if ( ! isset( self::get_runner()->assoc_args[ 'completions' ] ) ) { self::$logger->error( self::error_to_string( $message ), $label ); } @@ -246,19 +250,20 @@ class WP_CLI { } static function get_config_path() { - return self::$runner->config_path; + return self::get_runner()->config_path; } static function get_config( $key = null ) { - if ( null === $key ) - return self::$runner->config; + if ( null === $key ) { + return self::get_runner()->config; + } - if ( !isset( self::$runner->config[ $key ] ) ) { + if ( !isset( self::get_runner()->config[ $key ] ) ) { self::warning( "Unknown config option '$key'." ); return null; } - return self::$runner->config[ $key ]; + return self::get_runner()->config[ $key ]; } private static function find_command_to_run( $args ) {