本文整理汇总了PHP中WP_CLI\Dispatcher\get_path函数的典型用法代码示例。如果您正苦于以下问题:PHP get_path函数的具体用法?PHP get_path怎么用?PHP get_path使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_path函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_initial_markdown
private static function get_initial_markdown($command)
{
$name = implode(' ', Dispatcher\get_path($command));
$binding = array('name' => $name, 'shortdesc' => $command->get_shortdesc());
$binding['synopsis'] = wordwrap("{$name} " . $command->get_synopsis(), 79);
if ($command->has_subcommands()) {
$binding['has-subcommands']['subcommands'] = self::render_subcommands($command);
}
return Utils\mustache_render('man.mustache', $binding);
}
示例2: is_command_disabled
/**
* Check whether a given command is disabled by the config
*
* @return bool
*/
public function is_command_disabled($command)
{
$path = implode(' ', array_slice(\WP_CLI\Dispatcher\get_path($command), 1));
return in_array($path, $this->config['disabled_commands']);
}
示例3: add_command
/**
* Add a command to the wp-cli list of commands
*
* @param string $name The name of the command that will be used in the CLI
* @param string $callable The command implementation as a class, function or closure
* @param array $args An associative array with additional parameters:
* 'before_invoke' => callback to execute before invoking the command
*/
public static function add_command($name, $callable, $args = array())
{
$valid = false;
if (is_object($callable) && $callable instanceof \Closure) {
$valid = true;
} else {
if (is_string($callable) && function_exists($callable)) {
$valid = true;
} else {
if (is_string($callable) && class_exists((string) $callable)) {
$valid = true;
} else {
if (is_object($callable)) {
$valid = true;
} else {
if (is_array($callable) && is_callable($callable)) {
$valid = true;
}
}
}
}
}
if (!$valid) {
if (is_array($callable)) {
$callable = array(get_class($callable[0]), $callable[1]);
}
WP_CLI::error(sprintf("Callable %s does not exist, and cannot be registered as `wp %s`.", json_encode($callable), $name));
}
if (isset($args['before_invoke'])) {
self::add_hook("before_invoke:{$name}", $args['before_invoke']);
}
$path = preg_split('/\\s+/', $name);
$leaf_name = array_pop($path);
$full_path = $path;
$command = self::get_root_command();
while (!empty($path)) {
$subcommand_name = $path[0];
$subcommand = $command->find_subcommand($path);
// create an empty container
if (!$subcommand) {
$subcommand = new Dispatcher\CompositeCommand($command, $subcommand_name, new \WP_CLI\DocParser(''));
$command->add_subcommand($subcommand_name, $subcommand);
}
$command = $subcommand;
}
$leaf_command = Dispatcher\CommandFactory::create($leaf_name, $callable, $command);
if (!$command->can_have_subcommands()) {
throw new Exception(sprintf("'%s' can't have subcommands.", implode(' ', Dispatcher\get_path($command))));
}
$command->add_subcommand($leaf_name, $leaf_command);
}
示例4: add_command
/**
* Add a command to the wp-cli list of commands
*
* @param string $name The name of the command that will be used in the CLI
* @param string $class The command implementation
* @param array $args An associative array with additional parameters:
* 'before_invoke' => callback to execute before invoking the command
*/
public static function add_command($name, $class, $args = array())
{
if (is_string($class) && !class_exists((string) $class)) {
WP_CLI::error(sprintf("Class '%s' does not exist.", $class));
}
if (isset($args['before_invoke'])) {
self::add_hook("before_invoke:{$name}", $args['before_invoke']);
}
$path = preg_split('/\\s+/', $name);
$leaf_name = array_pop($path);
$full_path = $path;
$command = self::get_root_command();
while (!empty($path)) {
$subcommand_name = $path[0];
$subcommand = $command->find_subcommand($path);
// create an empty container
if (!$subcommand) {
$subcommand = new Dispatcher\CompositeCommand($command, $subcommand_name, new \WP_CLI\DocParser(''));
$command->add_subcommand($subcommand_name, $subcommand);
}
$command = $subcommand;
}
$leaf_command = Dispatcher\CommandFactory::create($leaf_name, $class, $command);
if (!$command->can_have_subcommands()) {
throw new Exception(sprintf("'%s' can't have subcommands.", implode(' ', Dispatcher\get_path($command))));
}
$command->add_subcommand($leaf_name, $leaf_command);
}
示例5: add_command
/**
* Register a command to WP-CLI.
*
* WP-CLI supports using any callable class, function, or closure as a
* command. `WP_CLI::add_command()` is used for both internal and
* third-party command registration.
*
* Command arguments are parsed from PHPDoc by default, but also can be
* supplied as an optional third argument during registration.
*
* ```
* # Register a custom 'foo' command to output a supplied positional param.
* #
* # $ wp foo bar
* # Success: bar
*
* /**
* * My awesome closure command
* *
* * <message>
* * : An awesome message to display
* *
* * @when before_wp_load
* *\/
* $foo = function( $args ) {
* WP_CLI::success( $args[0] );
* };
* WP_CLI::add_command( 'foo', $foo );
* ```
*
* @access public
* @category Registration
*
* @param string $name Name for the command (e.g. "post list" or "site empty").
* @param string $callable Command implementation as a class, function or closure.
* @param array $args {
* Optional An associative array with additional registration parameters.
* 'before_invoke' => callback to execute before invoking the command,
* 'after_invoke' => callback to execute after invoking the command,
* 'shortdesc' => short description (80 char or less) for the command,
* 'synopsis' => the synopsis for the command (string or array),
* 'when' => execute callback on a named WP-CLI hook (e.g. before_wp_load),
* }
* @return true True on success, hard error if registration failed.
*/
public static function add_command($name, $callable, $args = array())
{
$valid = false;
if (is_callable($callable)) {
$valid = true;
} else {
if (is_string($callable) && class_exists((string) $callable)) {
$valid = true;
} else {
if (is_object($callable)) {
$valid = true;
}
}
}
if (!$valid) {
if (is_array($callable)) {
$callable[0] = is_object($callable[0]) ? get_class($callable[0]) : $callable[0];
$callable = array($callable[0], $callable[1]);
}
WP_CLI::error(sprintf("Callable %s does not exist, and cannot be registered as `wp %s`.", json_encode($callable), $name));
}
foreach (array('before_invoke', 'after_invoke') as $when) {
if (isset($args[$when])) {
self::add_hook("{$when}:{$name}", $args[$when]);
}
}
$path = preg_split('/\\s+/', $name);
$leaf_name = array_pop($path);
$full_path = $path;
$command = self::get_root_command();
while (!empty($path)) {
$subcommand_name = $path[0];
$subcommand = $command->find_subcommand($path);
// create an empty container
if (!$subcommand) {
$subcommand = new Dispatcher\CompositeCommand($command, $subcommand_name, new \WP_CLI\DocParser(''));
$command->add_subcommand($subcommand_name, $subcommand);
}
$command = $subcommand;
}
$leaf_command = Dispatcher\CommandFactory::create($leaf_name, $callable, $command);
if (!$command->can_have_subcommands()) {
throw new Exception(sprintf("'%s' can't have subcommands.", implode(' ', Dispatcher\get_path($command))));
}
if (isset($args['shortdesc'])) {
$leaf_command->set_shortdesc($args['shortdesc']);
}
if (isset($args['synopsis'])) {
if (is_string($args['synopsis'])) {
$leaf_command->set_synopsis($args['synopsis']);
} else {
if (is_array($args['synopsis'])) {
$synopsis = \WP_CLI\SynopsisParser::render($args['synopsis']);
$leaf_command->set_synopsis($synopsis);
$long_desc = '';
//.........这里部分代码省略.........
示例6: register_early_invoke
public function register_early_invoke($when, $command)
{
$this->_early_invoke[$when][] = array_slice(Dispatcher\get_path($command), 1);
}