WP_CLI\Dispatcher
CommandFactory::create
Create a new CompositeCommand (or Subcommand if class has __invoke())
Method of the class: CommandFactory{}
No Hooks.
Returns
null. Nothing (null).
Usage
$result = CommandFactory::create( $name, $callable, $parent );
- $name(string) (required)
- Represents how the command should be invoked.
- $callable(string|callable-string|callable|array) (required)
- A subclass of WP_CLI_Command, a function, or a closure.
- $parent(mixed) (required)
- The new command's parent Composite (or Root) command.
CommandFactory::create() CommandFactory::create code WP-CLI 2.13.0-alpha
public static function create( $name, $callable, $parent ) {
if ( ( is_object( $callable ) && ( $callable instanceof Closure ) )
|| ( is_string( $callable ) && function_exists( $callable ) ) ) {
$reflection = new ReflectionFunction( $callable );
$command = self::create_subcommand( $parent, $name, $callable, $reflection );
} elseif ( is_array( $callable ) && ( is_callable( $callable ) || Utils\is_valid_class_and_method_pair( $callable ) ) ) {
$reflection = new ReflectionClass( $callable[0] );
$command = self::create_subcommand(
$parent,
$name,
[ $callable[0], $callable[1] ],
$reflection->getMethod( $callable[1] )
);
} else {
$reflection = new ReflectionClass( $callable );
if ( $reflection->isSubclassOf( '\WP_CLI\Dispatcher\CommandNamespace' ) ) {
$command = self::create_namespace( $parent, $name, $callable );
} elseif ( $reflection->hasMethod( '__invoke' ) ) {
$class = is_object( $callable ) ? $callable : $reflection->name;
$command = self::create_subcommand(
$parent,
$name,
[ $class, '__invoke' ],
$reflection->getMethod( '__invoke' )
);
} else {
$command = self::create_composite_command( $parent, $name, $callable );
}
}
return $command;
}