Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
declare(strict_types=1);
4
 
5
namespace Dotenv\Store;
6
 
7
use Dotenv\Exception\InvalidPathException;
8
use Dotenv\Store\File\Reader;
9
 
10
final class FileStore implements StoreInterface
11
{
12
    /**
13
     * The file paths.
14
     *
15
     * @var string[]
16
     */
17
    private $filePaths;
18
 
19
    /**
20
     * Should file loading short circuit?
21
     *
22
     * @var bool
23
     */
24
    private $shortCircuit;
25
 
26
    /**
27
     * The file encoding.
28
     *
29
     * @var string|null
30
     */
31
    private $fileEncoding;
32
 
33
    /**
34
     * Create a new file store instance.
35
     *
36
     * @param string[]    $filePaths
37
     * @param bool        $shortCircuit
38
     * @param string|null $fileEncoding
39
     *
40
     * @return void
41
     */
42
    public function __construct(array $filePaths, bool $shortCircuit, string $fileEncoding = null)
43
    {
44
        $this->filePaths = $filePaths;
45
        $this->shortCircuit = $shortCircuit;
46
        $this->fileEncoding = $fileEncoding;
47
    }
48
 
49
    /**
50
     * Read the content of the environment file(s).
51
     *
52
     * @throws \Dotenv\Exception\InvalidEncodingException|\Dotenv\Exception\InvalidPathException
53
     *
54
     * @return string
55
     */
56
    public function read()
57
    {
58
        if ($this->filePaths === []) {
59
            throw new InvalidPathException('At least one environment file path must be provided.');
60
        }
61
 
62
        $contents = Reader::read($this->filePaths, $this->shortCircuit, $this->fileEncoding);
63
 
64
        if (\count($contents) > 0) {
65
            return \implode("\n", $contents);
66
        }
67
 
68
        throw new InvalidPathException(
69
            \sprintf('Unable to read any of the environment file(s) at [%s].', \implode(', ', $this->filePaths))
70
        );
71
    }
72
}