blob: 0702a536a4a5eff4eb27af9be5ccf52e4d47a3e4 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<?php
declare(strict_types=1);
/**
* @author: Alexander Kiryukhin <alexander@kiryukhin.su>
* @license: MIT
*/
namespace NeonXP\Dotenv\Loader;
use NeonXP\Dotenv\Exception\RuntimeException;
/**
* Class FileLoader
* @package NeonXP\Dotenv\Loader
*/
class FileLoader implements LoaderInterface
{
const COMMENT_LINE_REGEX = '/^\s*#/';
/**
* @inheritdoc
* @param string $filePath
* @return array
* @throws RuntimeException
*/
public function load(string $filePath = '.env'): array
{
if (!file_exists($filePath)) {
throw new RuntimeException("There is no {$filePath} file!");
}
$lines = file($filePath);
$lines = array_map('trim', $lines);
$lines = array_filter($lines, function (string $line) {
return trim($line) && !preg_match(self::COMMENT_LINE_REGEX, $line);
});
$lines = array_values($lines);
return $lines;
}
}
|