src/Phossa/Console/GetOpt.php
/**
     * Parse one argument at a time
     *
     * @param  string $arg specific argument
     * @param  array &$arguments all command line arguments
     * @return bool
     * @access protected
     */
Parse one argument at a time
@param  string $arg specific argument
@param  array &$arguments all command line arguments
@return bool
@access protected
Parse one argument at a time @param string $arg specific argument @param array &$arguments all command line arguments @return bool @access protected
protected function parseOne(
         $arg,
        array &$arguments
    ) {
        $value = false;
        $vse = $this->configs['valueSeperator'];
        if ($arg[1] == '-') {
            $short = false;
            $rem = substr($arg, 2);
            if (strpos($rem, '=') !== false) {
                list($o, $value) = explode('=', $rem);
                $opts = [ $o ];
            } else {
                $opts = [ $rem ];
            }
        } else {
            $short = true;
            $opts  = str_split(substr($arg, 1), 1);
        }
        foreach($opts as $j => $opt) {
            if (!isset($this->options[$opt])) {
                $this->error = Message::get(
                    Message::GETOPT_OPTION_UNKNOWN, $opt
                );
                return false;
            }
            $o = $this->options[$opt];
             case
            if ($value) return $o->setValue($value, $vse);
             needed, set $o value to empty ''
            if (!$o->needValue()) {
                $o->setValue();
                continue;
            }
            if (!$o->isValueRequired()) {
                if ($short && $j < sizeof($opts) - 1) {
                    $value = join('', array_slice($opts, $j + 1));
                    return $o->setValue($value, $vse);
                } else {
                    if (!list(, $value) = each($arguments))
                        return $o->setValue();
                    if ($value[0] == '-') {
                        current($arguments) ?
                            prev($arguments) :
                            end($arguments);
                        return $o->setValue();
                    }
                    return $o->setValue($value, $vse);
                }
            }
            if (!$short || $j == sizeof($opts) - 1) {
                if (!list(, $value) = each($arguments)) {
                    $this->error = Message::get(
                        Message::GETOPT_OPTION_MISSING, $opt
                    );
                    return false;
                }
                if ($value[0] == '-') {
                    $this->error = Message::get(
                        Message::GETOPT_OPTION_MISSING, $opt
                    );
                    return false;
                }
                return $o->setValue($value, $vse);
            } else {
                $value = join('', array_slice($opts, $j + 1));
                return $o->setValue($value, $vse);
            }
        }
        return true;
    }
protected function parseOne ( $ arg , array & $ arguments ) { $ value = false ; $ vse = $ this -> configs [ 'valueSeperator' ] ; if ( $ arg [ 1 ] == '-' ) { $ short = false ; $ rem = substr ( $ arg , 2 ) ; if ( strpos ( $ rem , '=' ) !== false ) { list ( $ o , $ value ) = explode ( '=' , $ rem ) ; $ opts = [ $ o ] ; } else { $ opts = [ $ rem ] ; } } else { $ short = true ; $ opts = str_split ( substr ( $ arg , 1 ) , 1 ) ; } foreach ( $ opts as $ j => $ opt ) { if ( ! isset ( $ this -> options [ $ opt ] ) ) { $ this -> error = Message :: get ( Message :: GETOPT_OPTION_UNKNOWN , $ opt ) ; return false ; } $ o = $ this -> options [ $ opt ] ; if ( $ value ) return $ o -> setValue ( $ value , $ vse ) ; if ( ! $ o -> needValue ( ) ) { $ o -> setValue ( ) ; continue ; } if ( ! $ o -> isValueRequired ( ) ) { if ( $ short && $ j < sizeof ( $ opts ) - 1 ) { $ value = join ( '' , array_slice ( $ opts , $ j + 1 ) ) ; return $ o -> setValue ( $ value , $ vse ) ; } else { if ( ! list ( , $ value ) = each ( $ arguments ) ) return $ o -> setValue ( ) ; if ( $ value [ 0 ] == '-' ) { current ( $ arguments ) ? prev ( $ arguments ) : end ( $ arguments ) ; return $ o -> setValue ( ) ; } return $ o -> setValue ( $ value , $ vse ) ; } } if ( ! $ short || $ j == sizeof ( $ opts ) - 1 ) { if ( ! list ( , $ value ) = each ( $ arguments ) ) { $ this -> error = Message :: get ( Message :: GETOPT_OPTION_MISSING , $ opt ) ; return false ; } if ( $ value [ 0 ] == '-' ) { $ this -> error = Message :: get ( Message :: GETOPT_OPTION_MISSING , $ opt ) ; return false ; } return $ o -> setValue ( $ value , $ vse ) ; } else { $ value = join ( '' , array_slice ( $ opts , $ j + 1 ) ) ; return $ o -> setValue ( $ value , $ vse ) ; } } return true ; }
Parse one argument at a time
 @param  string $arg specific argument
 @param  array &$arguments all command line arguments
 @return bool
 @access protected
Parse one argument at a time @param string $arg specific argument @param array &$arguments all command line arguments @return bool @access protected
/*# string */ /*# : bool */ // no value // value serpator // long option // --user=phossa // --user phossa // short option(s) '-x' OR '-xyz' // loop thru options // unknown option // --user=phossa case // no value needed, set $o value to empty '' // value needed but not required // short option, remaining is the value // look at the next argument // next argument (value) not found // next argument is another option, go back // next argument is a value // value is required // value not found // next arg is an option // short option