WP_CLI\Dispatcher

CommandFactory::create_subcommand()private staticWP-CLI 1.0

Create a new Subcommand instance.

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

Хуков нет.

Возвращает

null. Ничего (null).

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

$result = CommandFactory::create_subcommand( $parent, $name, $callable, $reflection );
$parent(разное) (обязательный)
The new command's parent Composite command
$name(строка|true|false) (обязательный)
Represents how the command should be invoked. If false, will be determined from the documented subject, represented by $reflection.
$callable(разное) (обязательный)
A callable function or closure, or class name and method
$reflection(объект) (обязательный)
Reflection instance, for doc parsing

Код CommandFactory::create_subcommand() WP-CLI 2.8.0-alpha

private static function create_subcommand( $parent, $name, $callable, $reflection ) {
	$doc_comment = self::get_doc_comment( $reflection );
	$docparser   = new DocParser( $doc_comment );

	if ( is_array( $callable ) ) {
		if ( ! $name ) {
			$name = $docparser->get_tag( 'subcommand' );
		}

		if ( ! $name ) {
			$name = $reflection->name;
		}
	}
	if ( ! $doc_comment ) {
		WP_CLI::debug( null === $doc_comment ? "Failed to get doc comment for {$name}." : "No doc comment for {$name}.", 'commandfactory' );
	}

	$when_invoked = function ( $args, $assoc_args ) use ( $callable ) {
		if ( is_array( $callable ) ) {
			$callable[0] = is_object( $callable[0] ) ? $callable[0] : new $callable[0]();
			call_user_func( [ $callable[0], $callable[1] ], $args, $assoc_args );
		} else {
			call_user_func( $callable, $args, $assoc_args );
		}
	};

	return new Subcommand( $parent, $name, $docparser, $when_invoked );
}