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\Repository\Adapter;
6
 
7
use PhpOption\Option;
8
use PhpOption\Some;
9
 
10
final class ArrayAdapter implements AdapterInterface
11
{
12
    /**
13
     * The variables and their values.
14
     *
15
     * @var array<string,string>
16
     */
17
    private $variables;
18
 
19
    /**
20
     * Create a new array adapter instance.
21
     *
22
     * @return void
23
     */
24
    private function __construct()
25
    {
26
        $this->variables = [];
27
    }
28
 
29
    /**
30
     * Create a new instance of the adapter, if it is available.
31
     *
32
     * @return \PhpOption\Option<\Dotenv\Repository\Adapter\AdapterInterface>
33
     */
34
    public static function create()
35
    {
36
        /** @var \PhpOption\Option<AdapterInterface> */
37
        return Some::create(new self());
38
    }
39
 
40
    /**
41
     * Read an environment variable, if it exists.
42
     *
43
     * @param non-empty-string $name
44
     *
45
     * @return \PhpOption\Option<string>
46
     */
47
    public function read(string $name)
48
    {
49
        return Option::fromArraysValue($this->variables, $name);
50
    }
51
 
52
    /**
53
     * Write to an environment variable, if possible.
54
     *
55
     * @param non-empty-string $name
56
     * @param string           $value
57
     *
58
     * @return bool
59
     */
60
    public function write(string $name, string $value)
61
    {
62
        $this->variables[$name] = $value;
63
 
64
        return true;
65
    }
66
 
67
    /**
68
     * Delete an environment variable, if possible.
69
     *
70
     * @param non-empty-string $name
71
     *
72
     * @return bool
73
     */
74
    public function delete(string $name)
75
    {
76
        unset($this->variables[$name]);
77
 
78
        return true;
79
    }
80
}