@@ -79,29 +79,45 @@ public function setImmutable($immutable = false)
7979 }
8080
8181 /**
82- * Load `.env` file in given directory .
82+ * Load the environment file from disk .
8383 *
8484 * @throws \Dotenv\Exception\InvalidPathException|\Dotenv\Exception\InvalidFileException
8585 *
8686 * @return array<string|null>
8787 */
8888 public function load ()
89+ {
90+ return $ this ->loadDirect (
91+ self ::findAndRead ($ this ->filePaths )
92+ );
93+ }
94+
95+ /**
96+ * Directly load the given string.
97+ *
98+ * @param string $content
99+ *
100+ * @throws \Dotenv\Exception\InvalidFileException
101+ *
102+ * @return array<string|null>
103+ */
104+ public function loadDirect ($ content )
89105 {
90106 return $ this ->processEntries (
91- Lines::process (self :: readLines ( $ this -> filePaths ))
107+ Lines::process (preg_split ( " /( \r\n | \n | \r )/ " , $ content ))
92108 );
93109 }
94110
95111 /**
96- * Attempt to read the lines from the files in order.
112+ * Attempt to read the files in order.
97113 *
98114 * @param string[] $filePaths
99115 *
100116 * @throws \Dotenv\Exception\InvalidPathException
101117 *
102118 * @return string[]
103119 */
104- private static function readLines (array $ filePaths )
120+ private static function findAndRead (array $ filePaths )
105121 {
106122 if ($ filePaths === []) {
107123 throw new InvalidPathException ('At least one environment file path must be provided. ' );
@@ -120,20 +136,17 @@ private static function readLines(array $filePaths)
120136 }
121137
122138 /**
123- * Read from the file, auto detecting line endings .
139+ * Read the given file .
124140 *
125141 * @param string $filePath
126142 *
127143 * @return \PhpOption\Option
128144 */
129145 private static function readFromFile ($ filePath )
130146 {
131- $ autodetect = ini_get ('auto_detect_line_endings ' );
132- ini_set ('auto_detect_line_endings ' , '1 ' );
133- $ lines = @file ($ filePath , FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES );
134- ini_set ('auto_detect_line_endings ' , $ autodetect );
147+ $ content = @file_get_contents ($ filePath );
135148
136- return Option::fromValue ($ lines , false );
149+ return Option::fromValue ($ content , false );
137150 }
138151
139152 /**
0 commit comments