本文整理汇总了PHP中WP_CLI::get_runner方法的典型用法代码示例。如果您正苦于以下问题:PHP WP_CLI::get_runner方法的具体用法?PHP WP_CLI::get_runner怎么用?PHP WP_CLI::get_runner使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WP_CLI
的用法示例。
在下文中一共展示了WP_CLI::get_runner方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* Execute arbitrary PHP code.
*
* ## OPTIONS
*
* <php-code>
* : The code to execute, as a string.
*
* [--skip-wordpress]
* : Execute code without loading WordPress.
*
* @when before_wp_load
*
* ## EXAMPLES
*
* $ wp eval 'echo WP_CONTENT_DIR;'
* /var/www/wordpress/wp-content
*
* $ wp eval 'echo rand();' --skip-wordpress
* 479620423
*/
public function __invoke($args, $assoc_args)
{
if (null === \WP_CLI\Utils\get_flag_value($assoc_args, 'skip-wordpress')) {
WP_CLI::get_runner()->load_wordpress();
}
eval($args[0]);
}
示例2: __invoke
/**
* Launch PHP's built-in web server for this specific WordPress installation.
*
* Uses `php -S` to launch a web server serving the WordPress webroot.
* <http://php.net/manual/en/features.commandline.webserver.php>
*
* ## OPTIONS
*
* [--host=<host>]
* : The hostname to bind the server to.
* ---
* default: localhost
* ---
*
* [--port=<port>]
* : The port number to bind the server to.
* ---
* default: 8080
* ---
*
* [--docroot=<path>]
* : The path to use as the document root.
*
* [--config=<file>]
* : Configure the server with a specific .ini file.
*
* ## EXAMPLES
*
* # Make the instance available on any address (with port 8080)
* $ wp server --host=0.0.0.0
* PHP 5.6.9 Development Server started at Tue May 24 01:27:11 2016
* Listening on http://0.0.0.0:8080
* Document root is /
* Press Ctrl-C to quit.
*
* # Run on port 80 (for multisite)
* $ sudo wp server --host=localhost.localdomain --port=80
* PHP 5.6.9 Development Server started at Tue May 24 01:30:06 2016
* Listening on http://localhost1.localdomain1:8080
* Document root is /
* Press Ctrl-C to quit.
*
* # Configure the server with a specific .ini file
* $ wp server --config=development.ini
* PHP 7.0.9 Development Server started at Mon Aug 22 12:09:04 2016
* Listening on http://localhost:8080
* Document root is /
* Press Ctrl-C to quit.
*
* @when before_wp_load
*/
function __invoke($_, $assoc_args)
{
$min_version = '5.4';
if (version_compare(PHP_VERSION, $min_version, '<')) {
WP_CLI::error("The `wp server` command requires PHP {$min_version} or newer.");
}
$defaults = array('host' => 'localhost', 'port' => 8080, 'docroot' => false, 'config' => get_cfg_var('cfg_file_path'));
$assoc_args = array_merge($defaults, $assoc_args);
$docroot = $assoc_args['docroot'];
if (!$docroot) {
$config_path = WP_CLI::get_runner()->project_config_path;
if (!$config_path) {
$docroot = ABSPATH;
} else {
$docroot = dirname($config_path);
}
}
$cmd = \WP_CLI\Utils\esc_cmd('%s -S %s -t %s -c %s %s', PHP_BINARY, $assoc_args['host'] . ':' . $assoc_args['port'], $docroot, $assoc_args['config'], \WP_CLI\Utils\extract_from_phar(WP_CLI_ROOT . '/php/router.php'));
$descriptors = array(STDIN, STDOUT, STDERR);
// https://bugs.php.net/bug.php?id=60181
$options = array();
if (\WP_CLI\Utils\is_windows()) {
$options["bypass_shell"] = TRUE;
}
exit(proc_close(proc_open($cmd, $descriptors, $pipes, NULL, NULL, $options)));
}
示例3: debug
/**
* Write a message to STDERR, prefixed with "Debug: ".
*
* @param string $message Message to write.
*/
public function debug($message)
{
if (\WP_CLI::get_runner()->config['debug']) {
$time = round(microtime(true) - WP_CLI_START_MICROTIME, 3);
$this->_line("{$message} ({$time}s)", 'Debug', '%B', STDERR);
}
}
示例4: get
/**
* Get a config option.
*
* @synopsis <key> [--format=<format>]
*
* @when before_wp_load
*/
public function get($args, $assoc_args)
{
list($key) = $args;
$extra_config = WP_CLI::get_runner()->extra_config;
if (isset($extra_config[$key])) {
$this->print_value($extra_config[$key], $assoc_args);
}
}
示例5: __construct
function __construct()
{
$this->isWpCli = defined('WP_CLI') && WP_CLI;
if ($this->isWpCli) {
$runner = \WP_CLI::get_runner();
$this->wpCliArguments = $runner->arguments;
}
}
示例6: __invoke
/**
* Load and execute a PHP file.
*
* ## OPTIONS
*
* <file>
* : The path to the PHP file to execute.
*
* [<arg>...]
* : One or more arguments to pass to the file. They are placed in the $args variable.
*
* [--skip-wordpress]
* : Load and execute file without loading WordPress.
*
* @when before_wp_load
*
* ## EXAMPLES
*
* wp eval-file my-code.php value1 value2
*/
public function __invoke($args, $assoc_args)
{
$file = array_shift($args);
if (!file_exists($file)) {
WP_CLI::error("'{$file}' does not exist.");
}
if (null === \WP_CLI\Utils\get_flag_value($assoc_args, 'skip-wordpress')) {
WP_CLI::get_runner()->load_wordpress();
}
self::_eval($file, $args);
}
示例7: __construct
public function __construct($parent, $name, $docparser)
{
$this->parent = $parent;
$this->name = $name;
$this->shortdesc = $docparser->get_shortdesc();
$this->longdesc = $docparser->get_longdesc();
$when_to_invoke = $docparser->get_tag('when');
if ($when_to_invoke) {
\WP_CLI::get_runner()->register_early_invoke($when_to_invoke, $this);
}
}
示例8: is_plugin_skipped
function is_plugin_skipped($file)
{
$name = get_plugin_name(str_replace(WP_PLUGIN_DIR . '/', '', $file));
$skipped_plugins = \WP_CLI::get_runner()->config['skip-plugins'];
if (true === $skipped_plugins) {
return true;
}
if (!is_array($skipped_plugins)) {
$skipped_plugins = explode(',', $skipped_plugins);
}
return in_array($name, array_filter($skipped_plugins));
}
示例9: __invoke
/**
* Start a development server.
*
* ## OPTIONS
*
* --host=<host>
* : The hostname to bind the server to. Default: localhost
*
* --port=<port>
* : The port number to bind the server to. Default: 8080
*
* ## EXAMPLES
*
* # Make the instance available on any address (with port 8080)
* wp server --host=0.0.0.0
*
* # Run on port 80 (for multisite)
* sudo wp server --host=localhost.localdomain --port=80
*
* @when before_wp_load
* @synopsis [--host=<host>] [--port=<port>]
*/
function __invoke($_, $assoc_args)
{
$defaults = array('host' => 'localhost', 'port' => 8080);
$assoc_args = array_merge($defaults, $assoc_args);
$cmd = \WP_CLI\Utils\esc_cmd(PHP_BINARY . ' -S %s %s', $assoc_args['host'] . ':' . $assoc_args['port'], __DIR__ . '/router.php');
$config_path = WP_CLI::get_runner()->project_config_path;
if (!$config_path) {
$docroot = ABSPATH;
} else {
$docroot = dirname($config_path);
}
$descriptors = array(STDIN, STDOUT, STDERR);
exit(proc_close(proc_open($cmd, $descriptors, $pipes, $docroot)));
}
示例10: info
/**
* Print various data about the CLI environment.
*
* ## OPTIONS
*
* [--format=<format>]
* : Accepted values: json
*/
public function info($_, $assoc_args)
{
$php_bin = defined('PHP_BINARY') ? PHP_BINARY : getenv('WP_CLI_PHP_USED');
$runner = WP_CLI::get_runner();
if (\WP_CLI\Utils\get_flag_value($assoc_args, 'format') === 'json') {
$info = array('php_binary_path' => $php_bin, 'global_config_path' => $runner->global_config_path, 'project_config_path' => $runner->project_config_path, 'wp_cli_dir_path' => WP_CLI_ROOT, 'wp_cli_version' => WP_CLI_VERSION);
WP_CLI::line(json_encode($info));
} else {
WP_CLI::line("PHP binary:\t" . $php_bin);
WP_CLI::line("PHP version:\t" . PHP_VERSION);
WP_CLI::line("php.ini used:\t" . get_cfg_var('cfg_file_path'));
WP_CLI::line("WP-CLI root dir:\t" . WP_CLI_ROOT);
WP_CLI::line("WP-CLI global config:\t" . $runner->global_config_path);
WP_CLI::line("WP-CLI project config:\t" . $runner->project_config_path);
WP_CLI::line("WP-CLI version:\t" . WP_CLI_VERSION);
}
}
示例11: get_command
private function get_command($words)
{
$positional_args = $assoc_args = array();
foreach ($words as $arg) {
if (preg_match('|^--([^=]+)=?|', $arg, $matches)) {
$assoc_args[$matches[1]] = true;
} else {
$positional_args[] = $arg;
}
}
$r = \WP_CLI::get_runner()->find_command_to_run($positional_args);
if (!is_array($r) && array_pop($positional_args) == $this->cur_word) {
$r = \WP_CLI::get_runner()->find_command_to_run($positional_args);
}
if (!is_array($r)) {
return $r;
}
list($command, $args) = $r;
return array($command, $args, $assoc_args);
}
示例12: __invoke
/**
* Launch PHP's built-in web server for this specific WordPress installation.
*
* <http://php.net/manual/en/features.commandline.webserver.php>
*
* ## OPTIONS
*
* [--host=<host>]
* : The hostname to bind the server to. Default: localhost
*
* [--port=<port>]
* : The port number to bind the server to. Default: 8080
*
* [--docroot=<path>]
* : The path to use as the document root.
*
* ## EXAMPLES
*
* # Make the instance available on any address (with port 8080)
* wp server --host=0.0.0.0
*
* # Run on port 80 (for multisite)
* sudo wp server --host=localhost.localdomain --port=80
*
* @when before_wp_load
*/
function __invoke($_, $assoc_args)
{
$min_version = '5.4';
if (version_compare(PHP_VERSION, $min_version, '<')) {
WP_CLI::error("The `wp server` command requires PHP {$min_version} or newer.");
}
$defaults = array('host' => 'localhost', 'port' => 8080, 'docroot' => false);
$assoc_args = array_merge($defaults, $assoc_args);
$docroot = $assoc_args['docroot'];
if (!$docroot) {
$config_path = WP_CLI::get_runner()->project_config_path;
if (!$config_path) {
$docroot = ABSPATH;
} else {
$docroot = dirname($config_path);
}
}
$cmd = \WP_CLI\Utils\esc_cmd(PHP_BINARY . ' -S %s -t %s %s', $assoc_args['host'] . ':' . $assoc_args['port'], $docroot, \WP_CLI\Utils\extract_from_phar(WP_CLI_ROOT . '/php/router.php'));
$descriptors = array(STDIN, STDOUT, STDERR);
exit(proc_close(proc_open($cmd, $descriptors, $pipes)));
}
示例13: runWpCliCommand
public static function runWpCliCommand($command, $subcommand, $args = array(), $cwd = null)
{
$cliCommand = "wp {$command}";
if ($subcommand) {
$cliCommand .= " {$subcommand}";
}
// Colorize the output
if (defined('WP_CLI') && WP_CLI && \WP_CLI::get_runner()->in_color()) {
$args['color'] = null;
}
foreach ($args as $name => $value) {
if (is_int($name)) {
// positional argument
$cliCommand .= " " . escapeshellarg($value);
} elseif ($value !== null) {
$cliCommand .= " --{$name}=" . escapeshellarg($value);
} else {
$cliCommand .= " --{$name}";
}
}
return self::exec($cliCommand, $cwd);
}
示例14: alias
/**
* List available WP-CLI aliases.
*
* Aliases are shorthand references to WordPress installs. For instance,
* `@dev` could refer to a development install and `@prod` could refer to
* a production install. This command gives you visibility in what
* registered aliases you have available.
*
* ## OPTIONS
*
* [--format=<format>]
* : Render output in a particular format.
* ---
* default: yaml
* options:
* - yaml
* - json
* ---
*
* ## EXAMPLES
*
* # List all available aliases.
* $ wp cli alias
* ---
* @all: Run command against every registered alias.
* @prod:
* ssh: runcommand@runcommand.io~/webapps/production
* @dev:
* ssh: vagrant@192.168.50.10/srv/www/runcommand.dev
* @both:
* - @prod
* - @dev
*
* @alias aliases
*/
public function alias($_, $assoc_args)
{
WP_CLI::print_value(WP_CLI::get_runner()->aliases, $assoc_args);
}
示例15: define
<?php
// Can be used by plugins/themes to check if WP-CLI is running or not
define('WP_CLI', true);
define('WP_CLI_VERSION', '0.21.3');
define('WP_CLI_START_MICROTIME', microtime(true));
// Set common headers, to prevent warnings from plugins
$_SERVER['SERVER_PROTOCOL'] = 'HTTP/1.0';
$_SERVER['HTTP_USER_AGENT'] = '';
$_SERVER['REQUEST_METHOD'] = 'GET';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
include WP_CLI_ROOT . '/php/utils.php';
include WP_CLI_ROOT . '/php/dispatcher.php';
include WP_CLI_ROOT . '/php/class-wp-cli.php';
include WP_CLI_ROOT . '/php/class-wp-cli-command.php';
\WP_CLI\Utils\load_dependencies();
WP_CLI::get_runner()->start();