WP_CLI\Dispatcher

CommandFactory::create_subcommand()private staticWP-CLI 1.0

Create a new Subcommand instance.

Method of the class: CommandFactory{}

No Hooks.

Return

null. Nothing.

Usage

$result = CommandFactory::create_subcommand( $parent, $name, $callable, $reflection );
$parent(mixed) (required)
The new command's parent Composite command
$name(string|true|false) (required)
Represents how the command should be invoked. If false, will be determined from the documented subject, represented by $reflection.
$callable(mixed) (required)
A callable function or closure, or class name and method
$reflection(object) (required)
Reflection instance, for doc parsing

CommandFactory::create_subcommand() code 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 );
}