public function parse($content)
    {
        $tokens = $this->getTokens($content);

        $i = 0;
        $result = array();
        $currentMachine = '';

        while ($i < count($tokens)) {
            $currentToken = $tokens[$i];
            if ($currentToken == 'machine') {
                if (!isset($tokens[$i+1])) {
                    throw new ParseException("Cannot fetch machine name");
                }
                $currentMachine = $tokens[$i+1];
                $result[$currentMachine] = array();
                $i+=2;
            } else if ($currentToken == 'default') {
                $currentMachine = 'default';
                $result[$currentMachine] = array();
                $i++;
            } else {
                if (!in_array($currentToken, static::$netrcKeys)) {
                    throw new ParseException("Cannot handle unknown key '$currentToken' for '$currentMachine' machine");
                }
                if (!isset($tokens[$i+1])) {
                    throw new ParseException("Cannot fetch value of '$tokens[$i]' key for '$currentMachine' machine");
                }
                if (!$currentMachine) {
                    throw new ParseException("Cannot handle key '$currentToken' for unset machine");
                }
                $result[$currentMachine][$currentToken] = $tokens[$i+1];
                $i+=2;
            }
        }

        return $result;
    }
public function parse($content)
    {
        $tokens = $this->getTokens($content);

        $i = 0;
        $result = array();
        $currentMachine = '';

        while ($i < count($tokens)) {
            $currentToken = $tokens[$i];
            if ($currentToken == 'machine') {
                if (!isset($tokens[$i+1])) {
                    throw new ParseException("Cannot fetch machine name");
                }
                $currentMachine = $tokens[$i+1];
                $result[$currentMachine] = array();
                $i+=2;
            } else if ($currentToken == 'default') {
                $currentMachine = 'default';
                $result[$currentMachine] = array();
                $i++;
            } else {
                if (!in_array($currentToken, static::$netrcKeys)) {
                    throw new ParseException("Cannot handle unknown key '$currentToken' for '$currentMachine' machine");
                }
                if (!isset($tokens[$i+1])) {
                    throw new ParseException("Cannot fetch value of '$tokens[$i]' key for '$currentMachine' machine");
                }
                if (!$currentMachine) {
                    throw new ParseException("Cannot handle key '$currentToken' for unset machine");
                }
                $result[$currentMachine][$currentToken] = $tokens[$i+1];
                $i+=2;
            }
        }

        return $result;
    }
public function parse ( $ content ) { $ tokens = $ this -> getTokens ( $ content ) ; $ i = 0 ; $ result = array ( ) ; $ currentMachine = '' ; while ( $ i < count ( $ tokens ) ) { $ currentToken = $ tokens [ $ i ] ; if ( $ currentToken == 'machine' ) { if ( ! isset ( $ tokens [ $ i + 1 ] ) ) { throw new ParseException ( "Cannot fetch machine name" ) ; } $ currentMachine = $ tokens [ $ i + 1 ] ; $ result [ $ currentMachine ] = array ( ) ; $ i += 2 ; } else if ( $ currentToken == 'default' ) { $ currentMachine = 'default' ; $ result [ $ currentMachine ] = array ( ) ; $ i ++ ; } else { if ( ! in_array ( $ currentToken , static :: $ netrcKeys ) ) { throw new ParseException ( "Cannot handle unknown key '$currentToken' for '$currentMachine' machine" ) ; } if ( ! isset ( $ tokens [ $ i + 1 ] ) ) { throw new ParseException ( "Cannot fetch value of '$tokens[$i]' key for '$currentMachine' machine" ) ; } if ( ! $ currentMachine ) { throw new ParseException ( "Cannot handle key '$currentToken' for unset machine" ) ; } $ result [ $ currentMachine ] [ $ currentToken ] = $ tokens [ $ i + 1 ] ; $ i += 2 ; } } return $ result ; }
Parses netrc content

@param string $content file content

@throws ParseException when netrc file could not be parsed

@return array of netrc values grouped by machines
Parses netrc content