Example #1
0
 /**
  * Executes the action with the value entered by the user.
  *
  * @param mixed $value  The option value
  * @param array $params An array of optional parameters
  *
  * @return string
  * @throws PEAR2\Console\CommandLine\Exception
  */
 public function execute($value = false, $params = array())
 {
     if (!is_numeric($value)) {
         throw CommandLine\Exception::factory('OPTION_VALUE_TYPE_ERROR', array('name' => $this->option->name, 'type' => 'int', 'value' => $value), $this->parser);
     }
     $this->setResult((int) $value);
 }
Example #2
0
    /**
     * Formats the value $value according to the action of the option and 
     * updates the passed PEAR2\Console\CommandLine_Result object.
     *
     * @param mixed                            $value  The value to format
     * @param PEAR2\Console\CommandLine_Result $result The result instance
     * @param PEAR2\Console\CommandLine        $parser The parser instance
     *
     * @return void
     * @throws PEAR2\Console\CommandLine_Exception
     */
    public function dispatchAction($value, $result, $parser)
    {
        $actionInfo = Console\CommandLine::$actions[$this->action];
        $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);
    }