WP_CLI

DocParser::get_arg_or_param_args()privateWP-CLI 1.0

Get the args for an arg or param

Method of the class: DocParser{}

No Hooks.

Return

Array|null. Interpreted YAML document, or null.

Usage

// private - for code of main (parent) class only
$result = $this->get_arg_or_param_args( $regex );
$regex(string) (required)
Pattern to match against

DocParser::get_arg_or_param_args() code WP-CLI 2.8.0-alpha

private function get_arg_or_param_args( $regex ) {
	$bits       = explode( "\n", $this->doc_comment );
	$within_arg = false;
	$within_doc = false;
	$document   = [];
	foreach ( $bits as $bit ) {
		if ( preg_match( $regex, $bit ) ) {
			$within_arg = true;
		}

		if ( $within_arg && $within_doc && '---' === $bit ) {
			$within_doc = false;
		}

		if ( $within_arg && ! $within_doc && '---' === $bit ) {
			$within_doc = true;
		}

		if ( $within_doc ) {
			$document[] = $bit;
		}

		if ( $within_arg && '' === $bit ) {
			$within_arg = false;
			break;
		}
	}

	if ( $document ) {
		return Spyc::YAMLLoadString( implode( "\n", $document ) );
	}
	return null;
}