public static function fromString($argsString)
    {
        $argv = [ '' ];
        $argsString = trim($argsString);
        $argc = 0;

        if (empty($argsString)) {
            return new self([]);
        }

        $state = 'n'; // states: n (normal), d (double quoted), s (single quoted)
        for ($i = 0; $i < strlen($argsString); $i++) {
            $char = $argsString{$i};
            switch ($state) {
                case 'n':
                    if ($char === '\'') {
                        $state = 's';
                    } elseif ($char === '"') {
                        $state = 'd';
                    } elseif (in_array($char, [ "\n", "\t", ' ' ])) {
                        $argc++;
                        $argv[$argc] = '';
                    } else {
                        $argv[$argc] .= $char;
                    }
                    break;

                case 's':
                    if ($char === '\'') {
                        $state = 'n';
                    } elseif ($char === '\\') {
                        $i++;
                        $argv[$argc] .= $argsString{$i};
                    } else {
                        $argv[$argc] .= $char;
                    }
                    break;

                case 'd':
                    if ($char === '"') {
                        $state = 'n';
                    } elseif ($char === '\\') {
                        $i++;
                        $argv[$argc] .= $argsString{$i};
                    } else {
                        $argv[$argc] .= $char;
                    }
                    break;
            }
        }

        return new self($argv);
    }
public static function fromString($argsString)
    {
        $argv = [ '' ];
        $argsString = trim($argsString);
        $argc = 0;

        if (empty($argsString)) {
            return new self([]);
        }

        $state = 'n'; // states: n (normal), d (double quoted), s (single quoted)
        for ($i = 0; $i < strlen($argsString); $i++) {
            $char = $argsString{$i};
            switch ($state) {
                case 'n':
                    if ($char === '\'') {
                        $state = 's';
                    } elseif ($char === '"') {
                        $state = 'd';
                    } elseif (in_array($char, [ "\n", "\t", ' ' ])) {
                        $argc++;
                        $argv[$argc] = '';
                    } else {
                        $argv[$argc] .= $char;
                    }
                    break;

                case 's':
                    if ($char === '\'') {
                        $state = 'n';
                    } elseif ($char === '\\') {
                        $i++;
                        $argv[$argc] .= $argsString{$i};
                    } else {
                        $argv[$argc] .= $char;
                    }
                    break;

                case 'd':
                    if ($char === '"') {
                        $state = 'n';
                    } elseif ($char === '\\') {
                        $i++;
                        $argv[$argc] .= $argsString{$i};
                    } else {
                        $argv[$argc] .= $char;
                    }
                    break;
            }
        }

        return new self($argv);
    }
public static function fromString ( $ argsString ) { $ argv = [ '' ] ; $ argsString = trim ( $ argsString ) ; $ argc = 0 ; if ( empty ( $ argsString ) ) { return new self ( [ ] ) ; } $ state = 'n' ; // states: n (normal), d (double quoted), s (single quoted) for ( $ i = 0 ; $ i < strlen ( $ argsString ) ; $ i ++ ) { $ char = $ argsString { $ i } ; switch ( $ state ) { case 'n' : if ( $ char === '\'' ) { $ state = 's' ; } elseif ( $ char === '"' ) { $ state = 'd' ; } elseif ( in_array ( $ char , [ "\n" , "\t" , ' ' ] ) ) { $ argc ++ ; $ argv [ $ argc ] = '' ; } else { $ argv [ $ argc ] .= $ char ; } break ; case 's' : if ( $ char === '\'' ) { $ state = 'n' ; } elseif ( $ char === '\\' ) { $ i ++ ; $ argv [ $ argc ] .= $ argsString { $ i } ; } else { $ argv [ $ argc ] .= $ char ; } break ; case 'd' : if ( $ char === '"' ) { $ state = 'n' ; } elseif ( $ char === '\\' ) { $ i ++ ; $ argv [ $ argc ] .= $ argsString { $ i } ; } else { $ argv [ $ argc ] .= $ char ; } break ; } } return new self ( $ argv ) ; }
Parse arguments from argument string

@param string $argsString
@return Arguments
Parse arguments from argument string