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

GlobalAdapter::isSupported()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
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 global.
30
 * 
31
 * @author Alexander Campo <[email protected]>
32
 */
33
class GlobalAdapter 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
        global ${$name};
55
56
        return isset(${$name});
57
    }
58
59
    /**
60
     * Read an environment variable.
61
     * 
62
     * @param  string  $name
63
     * 
64
     * @return mixed
65
     */
66
    public function read(string $name)
67
    {
68
        if ($this->has($name)) {
69
            global ${$name};
70
71
            return ${$name};
72
        }
73
74
        return null;
75
    }
76
77
     /**
78
     * Write to an environment variable.
79
     * 
80
     * @param  string  $name
81
     * @param  string  $value
82
     * 
83
     * @return bool
84
     */
85
    public function write(string $name, string $value)
86
    {
87
        if ($this->has($name)) {
88
            global ${$name};
89
90
            ${$name} = $value;
91
        }
92
93
        return true;
94
    }
95
96
    /**
97
     * Delete an environment variable.
98
     * 
99
     * @param  string  $name
100
     * 
101
     * @return bool
102
     */
103
    public function delete(string $name)
104
    {
105
        global ${$name};
106
        
107
        unset(${$name});
108
109
        return true;
110
    }
111
}