Brotzka\DotenvEditor\DotenvEditor::envToArray PHP Method

envToArray() protected method

Writes the content of a env file to an array.
protected envToArray ( $file ) : array
$file
return array
    protected function envToArray($file)
    {
        $string = file_get_contents($file);
        $string = preg_split('/\\n+/', $string);
        $returnArray = array();
        foreach ($string as $one) {
            if (preg_match('/^(#\\s)/', $one) === 1) {
                continue;
            }
            $entry = explode("=", $one, 2);
            $returnArray[$entry[0]] = isset($entry[1]) ? $entry[1] : null;
        }
        return array_filter($returnArray, function ($key) {
            return !empty($key);
        }, ARRAY_FILTER_USE_KEY);
    }