Passed
Push — 0.7.0 ( a316e5...a89e02 )
by Alexander
03:01
created

EnvAdapter::write()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 5
rs 10
1
<?php 
2
3
/**
4
 * Lenevor Framework
5
 *
6
 * LICENSE
7
 *
8
 * This source file is subject to the new BSD license that is bundled
9
 * with this package in the file LICENSE.
10
 * It is also available through the world-wide-web at this URL:
11
 * https://lenevor.com/license
12
 * If you did not receive a copy of the license and are unable to
13
 * obtain it through the world-wide-web, please send an email
14
 * to [email protected] so we can send you a copy immediately.
15
 *
16
 * @package     Lenevor
17
 * @subpackage  Base
18
 * @link        https://lenevor.com
19
 * @copyright   Copyright (c) 2019 - 2021 Alexander Campo <[email protected]>
20
 * @license     https://opensource.org/licenses/BSD-3-Clause New BSD license or see https://lenevor.com/license or see /LICENSE
21
 */
22
23
namespace Syscodes\Dotenv\Repository\Adapters;
24
25
use Syscodes\Contracts\Dotenv\Adapter;
26
27
/**
28
 * Read, write and delete an environment variable for 
29
 * process of env.
30
 * 
31
 * @author Alexander Campo <[email protected]>
32
 */
33
class EnvAdapter implements Adapter
34
{
35
    /**
36
     * Determines if the adapter is supported.
37
     * 
38
     * @return bool
39
     */
40
    public function isSupported()
41
    {
42
        return true;
43
    }
44
45
    /**
46
     * Check if a variable exists.
47
     * 
48
     * @param  string  $name
49
     * 
50
     * @return bool
51
     */
52
    public function has(string $name)
53
    {
54
        return array_key_exists($name, $_ENV);
55
    }
56
57
    /**
58
     * Read an environment variable.
59
     * 
60
     * @param  string  $name
61
     * 
62
     * @return mixed
63
     */
64
    public function read(string $name)
65
    {
66
        if ($this->has($name)) {
67
            return $_ENV[$name];
68
        }
69
70
        return null;
71
    }
72
73
     /**
74
     * Write to an environment variable.
75
     * 
76
     * @param  string  $name
77
     * @param  string  $value
78
     * 
79
     * @return bool
80
     */
81
    public function write(string $name, string $value)
82
    {
83
        $_ENV[$name] = $value;
84
85
        return true;
86
    }
87
88
    /**
89
     * Delete an environment variable.
90
     * 
91
     * @param  string  $name
92
     * 
93
     * @return bool
94
     */
95
    public function delete(string $name)
96
    {
97
        unset($_ENV[$name]);
98
99
        return true;
100
    }
101
}