WP_CLI\Dispatcher

CommandFactory::create()public staticWP-CLI 1.0

Create a new CompositeCommand (or Subcommand if class has __invoke())

Метод класса: CommandFactory{}

Хуков нет.

Возвращает

null. Ничего.

Использование

$result = CommandFactory::create( $name, $callable, $parent );
$name(строка) (обязательный)
Represents how the command should be invoked
$callable(строка) (обязательный)
A subclass of WP_CLI_Command, a function, or a closure
$parent(разное) (обязательный)
The new command's parent Composite (or Root) command

Код CommandFactory::create() WP-CLI 2.8.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;
}