Console/Getopt.php
protected static function _parseLongOption($arg, $long_options, &$opts, &$argIdx, $args, $skip_unknown)
    {
        @list($opt, $opt_arg) = explode('=', $arg, 2);

        $opt_len = strlen($opt);

        for ($i = 0; $i < count($long_options); $i++) {
            $long_opt  = $long_options[$i];
            $opt_start = substr($long_opt, 0, $opt_len);

            $long_opt_name = str_replace('=', '', $long_opt);

            /* Option doesn't match. Go on to the next one. */
            if ($long_opt_name != $opt) {
                continue;
            }

            $opt_rest = substr($long_opt, $opt_len);

            /* Check that the options uniquely matches one of the allowed
               options. */
            if ($i + 1 < count($long_options)) {
                $next_option_rest = substr($long_options[$i + 1], $opt_len);
            } else {
                $next_option_rest = '';
            }

            if ($opt_rest != '' && $opt{0} != '=' &&
                $i + 1 < count($long_options) &&
                $opt == substr($long_options[$i+1], 0, $opt_len) &&
                $next_option_rest != '' &&
                $next_option_rest{0} != '=') {

                $msg = "Console_Getopt: option --$opt is ambiguous";
                return PEAR::raiseError($msg);
            }

            if (substr($long_opt, -1) == '=') {
                if (substr($long_opt, -2) != '==') {
                    /* Long option requires an argument.
                       Take the next argument if one wasn't specified. */;
                    if (!strlen($opt_arg)) {
                        if (!isset($args[++$argIdx])) {
                            $msg = "Console_Getopt: option requires an argument --$opt";
                            return PEAR::raiseError($msg);
                        }
                        $opt_arg = $args[$argIdx];
                    }

                    if (Console_Getopt::_isShortOpt($opt_arg)
                        || Console_Getopt::_isLongOpt($opt_arg)) {
                        $msg = "Console_Getopt: option requires an argument --$opt";
                        return PEAR::raiseError($msg);
                    }
                }
            } else if ($opt_arg) {
                $msg = "Console_Getopt: option --$opt doesn't allow an argument";
                return PEAR::raiseError($msg);
            }

            $opts[] = array('--' . $opt, $opt_arg);
            return;
        }

        if ($skip_unknown === true) {
            return;
        }

        return PEAR::raiseError("Console_Getopt: unrecognized option --$opt");
    }
protected static function _parseLongOption($arg, $long_options, &$opts, &$argIdx, $args, $skip_unknown)
    {
        @list($opt, $opt_arg) = explode('=', $arg, 2);

        $opt_len = strlen($opt);

        for ($i = 0; $i < count($long_options); $i++) {
            $long_opt  = $long_options[$i];
            $opt_start = substr($long_opt, 0, $opt_len);

            $long_opt_name = str_replace('=', '', $long_opt);

            /* Option doesn't match. Go on to the next one. */
            if ($long_opt_name != $opt) {
                continue;
            }

            $opt_rest = substr($long_opt, $opt_len);

            /* Check that the options uniquely matches one of the allowed
               options. */
            if ($i + 1 < count($long_options)) {
                $next_option_rest = substr($long_options[$i + 1], $opt_len);
            } else {
                $next_option_rest = '';
            }

            if ($opt_rest != '' && $opt{0} != '=' &&
                $i + 1 < count($long_options) &&
                $opt == substr($long_options[$i+1], 0, $opt_len) &&
                $next_option_rest != '' &&
                $next_option_rest{0} != '=') {

                $msg = "Console_Getopt: option --$opt is ambiguous";
                return PEAR::raiseError($msg);
            }

            if (substr($long_opt, -1) == '=') {
                if (substr($long_opt, -2) != '==') {
                    /* Long option requires an argument.
                       Take the next argument if one wasn't specified. */;
                    if (!strlen($opt_arg)) {
                        if (!isset($args[++$argIdx])) {
                            $msg = "Console_Getopt: option requires an argument --$opt";
                            return PEAR::raiseError($msg);
                        }
                        $opt_arg = $args[$argIdx];
                    }

                    if (Console_Getopt::_isShortOpt($opt_arg)
                        || Console_Getopt::_isLongOpt($opt_arg)) {
                        $msg = "Console_Getopt: option requires an argument --$opt";
                        return PEAR::raiseError($msg);
                    }
                }
            } else if ($opt_arg) {
                $msg = "Console_Getopt: option --$opt doesn't allow an argument";
                return PEAR::raiseError($msg);
            }

            $opts[] = array('--' . $opt, $opt_arg);
            return;
        }

        if ($skip_unknown === true) {
            return;
        }

        return PEAR::raiseError("Console_Getopt: unrecognized option --$opt");
    }
protected static function _parseLongOption ( $ arg , $ long_options , & $ opts , & $ argIdx , $ args , $ skip_unknown ) { @ list ( $ opt , $ opt_arg ) = explode ( '=' , $ arg , 2 ) ; $ opt_len = strlen ( $ opt ) ; for ( $ i = 0 ; $ i < count ( $ long_options ) ; $ i ++ ) { $ long_opt = $ long_options [ $ i ] ; $ opt_start = substr ( $ long_opt , 0 , $ opt_len ) ; $ long_opt_name = str_replace ( '=' , '' , $ long_opt ) ; /* Option doesn't match. Go on to the next one. */ if ( $ long_opt_name != $ opt ) { continue ; } $ opt_rest = substr ( $ long_opt , $ opt_len ) ; /* Check that the options uniquely matches one of the allowed
               options. */ if ( $ i + 1 < count ( $ long_options ) ) { $ next_option_rest = substr ( $ long_options [ $ i + 1 ] , $ opt_len ) ; } else { $ next_option_rest = '' ; } if ( $ opt_rest != '' && $ opt { 0 } != '=' && $ i + 1 < count ( $ long_options ) && $ opt == substr ( $ long_options [ $ i + 1 ] , 0 , $ opt_len ) && $ next_option_rest != '' && $ next_option_rest { 0 } != '=' ) { $ msg = "Console_Getopt: option --$opt is ambiguous" ; return PEAR :: raiseError ( $ msg ) ; } if ( substr ( $ long_opt , - 1 ) == '=' ) { if ( substr ( $ long_opt , - 2 ) != '==' ) { /* Long option requires an argument.
                       Take the next argument if one wasn't specified. */ ; if ( ! strlen ( $ opt_arg ) ) { if ( ! isset ( $ args [ ++ $ argIdx ] ) ) { $ msg = "Console_Getopt: option requires an argument --$opt" ; return PEAR :: raiseError ( $ msg ) ; } $ opt_arg = $ args [ $ argIdx ] ; } if ( Console_Getopt :: _isShortOpt ( $ opt_arg ) || Console_Getopt :: _isLongOpt ( $ opt_arg ) ) { $ msg = "Console_Getopt: option requires an argument --$opt" ; return PEAR :: raiseError ( $ msg ) ; } } } else if ( $ opt_arg ) { $ msg = "Console_Getopt: option --$opt doesn't allow an argument" ; return PEAR :: raiseError ( $ msg ) ; } $ opts [ ] = array ( '--' . $ opt , $ opt_arg ) ; return ; } if ( $ skip_unknown === true ) { return ; } return PEAR :: raiseError ( "Console_Getopt: unrecognized option --$opt" ) ; }
Parse long option

@param string     $arg          Argument
@param string[]   $long_options Available long options
@param string[][] &$opts
@param int        &$argIdx
@param string[]   $args

@return void|PEAR_Error
Parse long option