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SׇK%a,-}XHJ)tY;RJ vӓ;+fQGmAgJ$MQ]V b2AdQ6_n *H)aeڅ(+p qFMl @O_3Ȋoxc%4hyeP0TJ̕@v/{RǠWդn!oN Ў S\Sk%+ ۸q&^?P'BA<}3jq1*?j.Z\'̔>J?㗵zg@UFEt*L J6ݳCE3y;Gt8fڭv%K7NC-UǮ229ut'"|HH2'X]sk0O@RLa@{w8_option Whether to add a list option or not */ public $add_list_option = false; // }}} // Private properties {{{ /** * When an action is called remember it to allow for multiple calls. * * @var object $action_instance Placeholder for action */ private $_action_instance = null; // }}} // __construct() {{{ /** * Constructor. * * @param string $name The name of the option * @param array $params An optional array of parameters * * @return void */ public function __construct($name = null, $params = array()) { parent::__construct($name, $params); if ($this->action == 'Password') { // special case for Password action, password can be passed to the // commandline or prompted by the parser $this->argument_optional = true; } } // }}} // toString() {{{ /** * Returns the string representation of the option. * * @param string $delim Delimiter to use between short and long option * * @return string The string representation of the option * @todo use __toString() instead */ public function toString($delim = ", ") { $ret = ''; $padding = ''; if ($this->short_name != null) { $ret .= $this->short_name; if ($this->expectsArgument()) { $ret .= ' ' . $this->help_name; } $padding = $delim; } if ($this->long_name != null) { $ret .= $padding . $this->long_name; if ($this->expectsArgument()) { $ret .= '=' . $this->help_name; } } return $ret; } // }}} // expectsArgument() {{{ /** * Returns true if the option requires one or more argument and false * otherwise. * * @return bool Whether the option expects an argument or not */ public function expectsArgument() { if ($this->action == 'StoreTrue' || $this->action == 'StoreFalse' || $this->action == 'Help' || $this->action == 'Version' || $this->action == 'Counter' || $this->action == 'List') { return false; } return true; } // }}} // dispatchAction() {{{ /** * Formats the value $value according to the action of the option and * updates the passed Console_CommandLine_Result object. * * @param mixed $value The value to format * @param Console_CommandLine_Result $result The result instance * @param Console_CommandLine $parser The parser instance * * @return void * @throws Console_CommandLine_Exception */ public function dispatchAction($value, $result, $parser) { $actionInfo = Console_CommandLine::$actions[$this->action]; if (true === $actionInfo[1]) { // we have a "builtin" action $tokens = explode('_', $actionInfo[0]); include_once implode('/', $tokens) . '.php'; } $clsname = $actionInfo[0]; if ($this->_action_instance === null) { $this->_action_instance = new $clsname($result, $this, $parser); } // check value is in option choices if (!empty($this->choices) && !in_array($this->_action_instance->format($value), $this->choices)) { throw Console_CommandLine_Exception::factory( 'OPTION_VALUE_NOT_VALID', array( 'name' => $this->name, 'choices' => implode('", "', $this->choices), 'value' => $value, ), $parser, $this->messages ); } $this->_action_instance->execute($value, $this->action_params); } // }}} // validate() {{{ /** * Validates the option instance. * * @return void * @throws Console_CommandLine_Exception * @todo use exceptions instead */ public function validate() { // check if the option name is valid if (!preg_match('/^[a-zA-Z_\x7f-\xff]+[a-zA-Z0-9_\x7f-\xff]*$/', $this->name)) { Console_CommandLine::triggerError('option_bad_name', E_USER_ERROR, array('{$name}' => $this->name)); } // call the parent validate method parent::validate(); // a short_name or a long_name must be provided if ($this->short_name == null && $this->long_name == null) { Console_CommandLine::triggerError('option_long_and_short_name_missing', E_USER_ERROR, array('{$name}' => $this->name)); } // check if the option short_name is valid if ($this->short_name != null && !(preg_match('/^\-[a-zA-Z]{1}$/', $this->short_name))) { Console_CommandLine::triggerError('option_bad_short_name', E_USER_ERROR, array( '{$name}' => $this->name, '{$short_name}' => $this->short_name )); } // check if the option long_name is valid if ($this->long_name != null && !preg_match('/^\-\-[a-zA-Z]+[a-zA-Z0-9_\-]*$/', $this->long_name)) { Console_CommandLine::triggerError('option_bad_long_name', E_USER_ERROR, array( '{$name}' => $this->name, '{$long_name}' => $this->long_name )); } // check if we have a valid action if (!is_string($this->action)) { Console_CommandLine::triggerError('option_bad_action', E_USER_ERROR, array('{$name}' => $this->name)); } if (!isset(Console_CommandLine::$actions[$this->action])) { Console_CommandLine::triggerError('option_unregistered_action', E_USER_ERROR, array( '{$action}' => $this->action, '{$name}' => $this->name )); } // if the action is a callback, check that we have a valid callback if ($this->action == 'Callback' && !is_callable($this->callback)) { Console_CommandLine::triggerError('option_invalid_callback', E_USER_ERROR, array('{$name}' => $this->name)); } } // }}} // setDefaults() {{{ /** * Set the default value according to the configured action. * * Note that for backward compatibility issues this method is only called * when the 'force_options_defaults' is set to true, it will become the * default behaviour in the next major release of Console_CommandLine. * * @return void */ public function setDefaults() { if ($this->default !== null) { // already set return; } switch ($this->action) { case 'Counter': case 'StoreInt': $this->default = 0; break; case 'StoreFloat': $this->default = 0.0; break; case 'StoreArray': $this->default = array(); break; case 'StoreTrue': $this->default = false; break; case 'StoreFalse': $this->default = true; break; default: return; } } // }}} }