public function parse(string $data, string $path = '.env'): array
    {
        $this->path = $path;
        $this->data = str_replace(["\r\n", "\r"], "\n", $data);
        $this->lineno = 1;
        $this->cursor = 0;
        $this->end = \strlen($this->data);
        $state = self::STATE_VARNAME;
        $this->values = [];
        $name = '';

        $this->skipEmptyLines();

        while ($this->cursor < $this->end) {
            switch ($state) {
                case self::STATE_VARNAME:
                    $name = $this->lexVarname();
                    $state = self::STATE_VALUE;
                    break;

                case self::STATE_VALUE:
                    $this->values[$name] = $this->lexValue();
                    $state = self::STATE_VARNAME;
                    break;
            }
        }

        if (self::STATE_VALUE === $state) {
            $this->values[$name] = '';
        }

        try {
            return $this->values;
        } finally {
            $this->values = [];
            $this->data = null;
            $this->path = null;
        }
    }
public function parse(string $data, string $path = '.env'): array
    {
        $this->path = $path;
        $this->data = str_replace(["\r\n", "\r"], "\n", $data);
        $this->lineno = 1;
        $this->cursor = 0;
        $this->end = \strlen($this->data);
        $state = self::STATE_VARNAME;
        $this->values = [];
        $name = '';

        $this->skipEmptyLines();

        while ($this->cursor < $this->end) {
            switch ($state) {
                case self::STATE_VARNAME:
                    $name = $this->lexVarname();
                    $state = self::STATE_VALUE;
                    break;

                case self::STATE_VALUE:
                    $this->values[$name] = $this->lexValue();
                    $state = self::STATE_VARNAME;
                    break;
            }
        }

        if (self::STATE_VALUE === $state) {
            $this->values[$name] = '';
        }

        try {
            return $this->values;
        } finally {
            $this->values = [];
            $this->data = null;
            $this->path = null;
        }
    }
public function parse ( string $ data , string $ path = '.env' ) : array { $ this -> path = $ path ; $ this -> data = str_replace ( [ "\r\n" , "\r" ] , "\n" , $ data ) ; $ this -> lineno = 1 ; $ this -> cursor = 0 ; $ this -> end = \ strlen ( $ this -> data ) ; $ state = self :: STATE_VARNAME ; $ this -> values = [ ] ; $ name = '' ; $ this -> skipEmptyLines ( ) ; while ( $ this -> cursor < $ this -> end ) { switch ( $ state ) { case self :: STATE_VARNAME : $ name = $ this -> lexVarname ( ) ; $ state = self :: STATE_VALUE ; break ; case self :: STATE_VALUE : $ this -> values [ $ name ] = $ this -> lexValue ( ) ; $ state = self :: STATE_VARNAME ; break ; } } if ( self :: STATE_VALUE === $ state ) { $ this -> values [ $ name ] = '' ; } try { return $ this -> values ; } finally { $ this -> values = [ ] ; $ this -> data = null ; $ this -> path = null ; } }
Parses the contents of an .env file.

@param string $data The data to be parsed
@param string $path The original file name where data where stored (used for more meaningful error messages)

@return array An array of env variables

@throws FormatException when a file has a syntax error
Parses the contents of an . env file .