WP_CLI\Dispatcher

CommandAddition{}WP-CLI 1.0

Controls whether adding of a command should be completed or not.

This is needed because we can't reliably pass scalar values by reference through the hooks mechanism. An object is always passed by reference.

No Hooks.

Usage

$CommandAddition = new CommandAddition();
// use class methods

Methods

  1. public abort( $reason = '' )
  2. public get_reason()
  3. public was_aborted()

Notes

  • Package: WP_CLI

CommandAddition{} code WP-CLI 2.8.0-alpha

final class CommandAddition {

	/**
	 * Whether the command addition was aborted or not.
	 *
	 * @var bool
	 */
	private $abort = false;

	/**
	 * Reason for which the addition was aborted.
	 *
	 * @var string
	 */
	private $reason = '';

	/**
	 * Abort the current command addition.
	 *
	 * @param string $reason Reason as to why the addition was aborted.
	 */
	public function abort( $reason = '' ) {
		$this->abort  = true;
		$this->reason = (string) $reason;
	}

	/**
	 * Check whether the command addition was aborted.
	 *
	 * @return bool
	 */
	public function was_aborted() {
		return $this->abort;
	}

	/**
	 * Get the reason as to why the addition was aborted.
	 *
	 * @return string
	 */
	public function get_reason() {
		return $this->reason;
	}
}