-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathLoader.php
49 lines (38 loc) · 1.32 KB
/
Loader.php
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
42
43
44
45
46
47
48
49
<?php
namespace Snowair\Dotenv;
use Snowair\Dotenv\Parser;
class Loader extends \josegonzalez\Dotenv\Loader
{
public function parse()
{
$contents = false;
$filepaths = $this->filepaths();
foreach ($filepaths as $i => $filepath) {
$isLast = count($filepaths) - 1 === $i;
if (!file_exists($filepath) && $isLast) {
return $this->raise(
'InvalidArgumentException',
sprintf("Environment file '%s' is not found", $filepath)
);
}
if (is_dir($filepath) && $isLast) {
return $this->raise(
'InvalidArgumentException',
sprintf("Environment file '%s' is a directory. Should be a file", $filepath)
);
}
if ((!is_readable($filepath) || ($contents = file_get_contents($filepath)) === false) && $isLast) {
return $this->raise(
'InvalidArgumentException',
sprintf("Environment file '%s' is not readable", $filepath)
);
}
if ($contents !== false) {
break;
}
}
$parser = new Parser;
$this->environment = $parser->parse($contents);
return $this;
}
}