示例#1
0
 /**
  * 
  * Public interface to execute the command.
  * 
  * This method...
  * 
  * - populates and validates the option values
  * - calls _preExec()
  * - calls _exec() with the numeric parameters from the options
  * - calls _postExec()
  * 
  * @param array $argv The command-line arguments from the user.
  * 
  * @return void
  * 
  * @todo Accept a Getopt object in addition to $argv array?
  * 
  */
 public function exec($argv = null)
 {
     // get the command-line arguments
     if ($argv === null) {
         // use the $_SERVER values
         $argv = $this->_request->server['argv'];
         // remove the argument pointing to this command
         array_shift($argv);
     } else {
         $argv = (array) $argv;
     }
     // set options, populate values, and validate parameters
     $this->_getopt->populate($argv);
     if (!$this->_getopt->validate()) {
         // need a better way to throw exceptions with specific error
         // messages
         throw $this->_exception('ERR_INVALID_OPTIONS', array('invalid' => $this->_getopt->getInvalid(), 'options' => $this->_getopt->options));
     }
     // retain the option values, minus the numeric params
     $this->_options = $this->_getopt->values();
     $params = array();
     foreach ($this->_options as $key => $val) {
         if (is_int($key)) {
             $params[] = $val;
             unset($this->_options[$key]);
         }
     }
     // special behavior for -V/--version
     if ($this->_options['version']) {
         $vendor = Solar_Class::vendor($this);
         $this->_out("{$vendor} command-line tool, Solar version ");
         $this->_outln(Solar::apiVersion() . '.');
         return;
     }
     // call pre-exec
     $skip_exec = $this->_preExec();
     // should we skip the main execution?
     if ($skip_exec !== true) {
         // call _exec() with the numeric params from getopt
         call_user_func_array(array($this, '_exec'), $params);
     }
     // call post-exec
     $this->_postExec();
     // done, return terminal to normal colors
     $this->_out("%n");
 }
示例#2
0
 /**
  * 
  * Public interface to execute the command.
  * 
  * This method...
  * 
  * - populates and validates the option values
  * - calls _preExec()
  * - calls _exec() with the numeric parameters from the options
  * - calls _postExec()
  * 
  * @param array $argv The command-line arguments from the user.
  * 
  * @return void
  * 
  * @todo Accept a Getopt object in addition to $argv array?
  * 
  */
 public function exec($argv = null)
 {
     // get the command-line arguments
     if ($argv === null) {
         // use the $_SERVER values
         $argv = $this->_request->server['argv'];
         // remove the argument pointing to this command
         array_shift($argv);
     } else {
         $argv = (array) $argv;
     }
     // set options, populate values, and validate parameters
     $this->_getopt->populate($argv);
     if (!$this->_getopt->validate()) {
         // need a better way to throw exceptions with specific error
         // messages
         throw $this->_exception('ERR_INVALID_OPTIONS', $this->_getopt->getInvalid());
     }
     // retain the option values, minus the numeric params
     $this->_options = $this->_getopt->values();
     $params = array();
     foreach ($this->_options as $key => $val) {
         if (is_int($key)) {
             $params[] = $val;
             unset($this->_options[$key]);
         }
     }
     // call pre-exec
     $skip_exec = $this->_preExec();
     // should we skip the main execution?
     if ($skip_exec !== true) {
         // call _exec() with the numeric params from getopt
         call_user_func_array(array($this, '_exec'), $params);
     }
     // call post-exec, and we're done
     $this->_postExec();
 }