public function parseLine($line)
    {
        $output = [
            'type'    => null,
            'export'  => null,
            'key'     => null,
            'value'   => null,
            'comment' => null,
        ];

        if ($this->isEmpty($line)) {
            $output['type'] = 'empty';
        } elseif ($this->isComment($line)) {
            $output['type']    = 'comment';
            $output['comment'] = $this->normaliseComment($line);
        } elseif ($this->looksLikeSetter($line)) {
            list($key, $data) = array_map('trim', explode('=', $line, 2));
            $export = $this->isExportKey($key);
            $key    = $this->normaliseKey($key);
            $data   = trim($data);

            if (!$data && $data !== '0') {
                $value   = '';
                $comment = '';
            } else {
                if ($this->beginsWithAQuote($data)) { // data starts with a quote
                    $quote = $data[0];
                    $regexPattern = sprintf(
                        '/^
                        %1$s          # match a quote at the start of the data
                        (             # capturing sub-pattern used
                         (?:          # we do not need to capture this
                          [^%1$s\\\\] # any character other than a quote or backslash
                          |\\\\\\\\   # or two backslashes together
                          |\\\\%1$s   # or an escaped quote e.g \"
                         )*           # as many characters that match the previous rules
                        )             # end of the capturing sub-pattern
                        %1$s          # and the closing quote
                        (.*)$         # and discard any string after the closing quote
                        /mx',
                        $quote
                    );

                    $value  = preg_replace($regexPattern, '$1', $data);
                    $extant = preg_replace($regexPattern, '$2', $data);

                    $value = $this->normaliseValue($value, $quote);
                    $comment = ($this->isComment($extant)) ? $this->normaliseComment($extant) : '';
                } else {
                    $parts   = explode(' #', $data, 2);

                    $value   = $this->normaliseValue($parts[0]);
                    $comment = (isset($parts[1])) ? $this->normaliseComment($parts[1]) : '';

                    // Unquoted values cannot contain whitespace
                    if (preg_match('/\s+/', $value) > 0) {
                        throw new InvalidValueException('Dotenv values containing spaces must be surrounded by quotes.');
                    }
                }
            }

            $output['type']    = 'setter';
            $output['export']  = $export;
            $output['key']     = $key;
            $output['value']   = $value;
            $output['comment'] = $comment;
        } else {
            $output['type'] = 'unknown';
        }

        return $output;
    }
public function parseLine($line)
    {
        $output = [
            'type'    => null,
            'export'  => null,
            'key'     => null,
            'value'   => null,
            'comment' => null,
        ];

        if ($this->isEmpty($line)) {
            $output['type'] = 'empty';
        } elseif ($this->isComment($line)) {
            $output['type']    = 'comment';
            $output['comment'] = $this->normaliseComment($line);
        } elseif ($this->looksLikeSetter($line)) {
            list($key, $data) = array_map('trim', explode('=', $line, 2));
            $export = $this->isExportKey($key);
            $key    = $this->normaliseKey($key);
            $data   = trim($data);

            if (!$data && $data !== '0') {
                $value   = '';
                $comment = '';
            } else {
                if ($this->beginsWithAQuote($data)) { 
                    $quote = $data[0];
                    $regexPattern = sprintf(
                        '/^
                        %1$s          
                        (             
                         (?:          
                          [^%1$s\\\\] 
                          |\\\\\\\\   
                          |\\\\%1$s   
                         )*           
                        )             
                        %1$s          
                        (.*)$         
                        /mx',
                        $quote
                    );

                    $value  = preg_replace($regexPattern, '$1', $data);
                    $extant = preg_replace($regexPattern, '$2', $data);

                    $value = $this->normaliseValue($value, $quote);
                    $comment = ($this->isComment($extant)) ? $this->normaliseComment($extant) : '';
                } else {
                    $parts   = explode(' 

                    $value   = $this->normaliseValue($parts[0]);
                    $comment = (isset($parts[1])) ? $this->normaliseComment($parts[1]) : '';

                    
                    if (preg_match('/\s+/', $value) > 0) {
                        throw new InvalidValueException('Dotenv values containing spaces must be surrounded by quotes.');
                    }
                }
            }

            $output['type']    = 'setter';
            $output['export']  = $export;
            $output['key']     = $key;
            $output['value']   = $value;
            $output['comment'] = $comment;
        } else {
            $output['type'] = 'unknown';
        }

        return $output;
    }
public function parseLine ( $ line ) { $ output = [ 'type' => null , 'export' => null , 'key' => null , 'value' => null , 'comment' => null , ] ; if ( $ this -> isEmpty ( $ line ) ) { $ output [ 'type' ] = 'empty' ; } elseif ( $ this -> isComment ( $ line ) ) { $ output [ 'type' ] = 'comment' ; $ output [ 'comment' ] = $ this -> normaliseComment ( $ line ) ; } elseif ( $ this -> looksLikeSetter ( $ line ) ) { list ( $ key , $ data ) = array_map ( 'trim' , explode ( '=' , $ line , 2 ) ) ; $ export = $ this -> isExportKey ( $ key ) ; $ key = $ this -> normaliseKey ( $ key ) ; $ data = trim ( $ data ) ; if ( ! $ data && $ data !== '0' ) { $ value = '' ; $ comment = '' ; } else { if ( $ this -> beginsWithAQuote ( $ data ) ) { // data starts with a quote $ quote = $ data [ 0 ] ; $ regexPattern = sprintf ( '/^
                        %1$s          # match a quote at the start of the data
                        (             # capturing sub-pattern used
                         (?:          # we do not need to capture this
                          [^%1$s\\\\] # any character other than a quote or backslash
                          |\\\\\\\\   # or two backslashes together
                          |\\\\%1$s   # or an escaped quote e.g \"
                         )*           # as many characters that match the previous rules
                        )             # end of the capturing sub-pattern
                        %1$s          # and the closing quote
                        (.*)$         # and discard any string after the closing quote
                        /mx' , $ quote ) ; $ value = preg_replace ( $ regexPattern , '$1' , $ data ) ; $ extant = preg_replace ( $ regexPattern , '$2' , $ data ) ; $ value = $ this -> normaliseValue ( $ value , $ quote ) ; $ comment = ( $ this -> isComment ( $ extant ) ) ? $ this -> normaliseComment ( $ extant ) : '' ; } else { $ parts = explode ( ' #' , $ data , 2 ) ; $ value = $ this -> normaliseValue ( $ parts [ 0 ] ) ; $ comment = ( isset ( $ parts [ 1 ] ) ) ? $ this -> normaliseComment ( $ parts [ 1 ] ) : '' ; // Unquoted values cannot contain whitespace if ( preg_match ( '/\s+/' , $ value ) > 0 ) { throw new InvalidValueException ( 'Dotenv values containing spaces must be surrounded by quotes.' ) ; } } } $ output [ 'type' ] = 'setter' ; $ output [ 'export' ] = $ export ; $ output [ 'key' ] = $ key ; $ output [ 'value' ] = $ value ; $ output [ 'comment' ] = $ comment ; } else { $ output [ 'type' ] = 'unknown' ; } return $ output ; }
Parse a line into an array of type, export, key, value and comment

@param  string $line

@throws \Jackiedo\DotenvEditor\Exceptions\InvalidValueException

@return array
Parse a line into an array of type export key value and comment