src/Ulrichsg/Getopt/CommandLineParser.php
public function parse($arguments)
    {
        if (!is_array($arguments)) {
            $arguments = explode(' ', $arguments);
        }
        $operands = array();
        $numArgs = count($arguments);
        for ($i = 0; $i < $numArgs; ++$i) {
            $arg = trim($arguments[$i]);
            if (empty($arg)) {
                continue;
            }
            if (($arg === '--') || ($arg === '-') || (mb_substr($arg, 0, 1) !== '-')){
                // no more options, treat the remaining arguments as operands
                $firstOperandIndex = ($arg == '--') ? $i + 1 : $i;
                $operands = array_slice($arguments, $firstOperandIndex);
                break;
            }
            if (mb_substr($arg, 0, 2) == '--') {
                $this->addLongOption($arguments, $i);
            } else {
                $this->addShortOption($arguments, $i);
            }
        } // endfor

        $this->addDefaultValues();

        // remove '--' from operands array
        foreach ($operands as $operand) {
            if ($operand !== '--') {
                $this->operands[] = $operand;
            }
        }
    }
public function parse($arguments)
    {
        if (!is_array($arguments)) {
            $arguments = explode(' ', $arguments);
        }
        $operands = array();
        $numArgs = count($arguments);
        for ($i = 0; $i < $numArgs; ++$i) {
            $arg = trim($arguments[$i]);
            if (empty($arg)) {
                continue;
            }
            if (($arg === '--') || ($arg === '-') || (mb_substr($arg, 0, 1) !== '-')){
                // no more options, treat the remaining arguments as operands
                $firstOperandIndex = ($arg == '--') ? $i + 1 : $i;
                $operands = array_slice($arguments, $firstOperandIndex);
                break;
            }
            if (mb_substr($arg, 0, 2) == '--') {
                $this->addLongOption($arguments, $i);
            } else {
                $this->addShortOption($arguments, $i);
            }
        } // endfor

        $this->addDefaultValues();

        // remove '--' from operands array
        foreach ($operands as $operand) {
            if ($operand !== '--') {
                $this->operands[] = $operand;
            }
        }
    }
public function parse ( $ arguments ) { if ( ! is_array ( $ arguments ) ) { $ arguments = explode ( ' ' , $ arguments ) ; } $ operands = array ( ) ; $ numArgs = count ( $ arguments ) ; for ( $ i = 0 ; $ i < $ numArgs ; ++ $ i ) { $ arg = trim ( $ arguments [ $ i ] ) ; if ( empty ( $ arg ) ) { continue ; } if ( ( $ arg === '--' ) || ( $ arg === '-' ) || ( mb_substr ( $ arg , 0 , 1 ) !== '-' ) ) { // no more options, treat the remaining arguments as operands $ firstOperandIndex = ( $ arg == '--' ) ? $ i + 1 : $ i ; $ operands = array_slice ( $ arguments , $ firstOperandIndex ) ; break ; } if ( mb_substr ( $ arg , 0 , 2 ) == '--' ) { $ this -> addLongOption ( $ arguments , $ i ) ; } else { $ this -> addShortOption ( $ arguments , $ i ) ; } } // endfor $ this -> addDefaultValues ( ) ; // remove '--' from operands array foreach ( $ operands as $ operand ) { if ( $ operand !== '--' ) { $ this -> operands [ ] = $ operand ; } } }
Parses the given arguments and converts them into options and operands.

@param mixed $arguments a string or an array with one argument per element
Parses the given arguments and converts them into options and operands .