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\Loader;
6
 
7
use Dotenv\Parser\Entry;
8
use Dotenv\Parser\Value;
9
use Dotenv\Repository\RepositoryInterface;
10
 
11
final class Loader implements LoaderInterface
12
{
13
    /**
14
     * Load the given entries into the repository.
15
     *
16
     * We'll substitute any nested variables, and send each variable to the
17
     * repository, with the effect of actually mutating the environment.
18
     *
19
     * @param \Dotenv\Repository\RepositoryInterface $repository
20
     * @param \Dotenv\Parser\Entry[]                 $entries
21
     *
22
     * @return array<string,string|null>
23
     */
24
    public function load(RepositoryInterface $repository, array $entries)
25
    {
26
        return \array_reduce($entries, static function (array $vars, Entry $entry) use ($repository) {
27
            $name = $entry->getName();
28
 
29
            $value = $entry->getValue()->map(static function (Value $value) use ($repository) {
30
                return Resolver::resolve($repository, $value);
31
            });
32
 
33
            if ($value->isDefined()) {
34
                $inner = $value->get();
35
                if ($repository->set($name, $inner)) {
36
                    return \array_merge($vars, [$name => $inner]);
37
                }
38
            } else {
39
                if ($repository->clear($name)) {
40
                    return \array_merge($vars, [$name => null]);
41
                }
42
            }
43
 
44
            return $vars;
45
        }, []);
46
    }
47
}