Completed
Push — master ( 47a2dd...c6902f )
by smiley
02:21
created

DotEnv::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Class DotEnv
4
 *
5
 * @filesource   DotEnv.php
6
 * @created      25.11.2017
7
 * @package      chillerlan\Traits
8
 * @author       Smiley <[email protected]>
9
 * @copyright    2017 Smiley
10
 * @license      MIT
11
 */
12
13
namespace chillerlan\Traits;
14
15
/**
16
 * @method bool|mixed __get(string $var)
17
 * @method bool|mixed get(string $var)
18
 * @method void __set(string $var, string $value = null)
19
 * @method DotEnv set(string $var, string $value = null)
20
 * @method DotEnv unset(string $var)
21
 * @method DotEnv clear()
22
 */
23
class DotEnv{
24
	use Env{
25
		// allow a magic getter & setter
26
		__getEnv as public __get;
27
		__setEnv as public __set;
28
		// as well as a generic ones
29
		__getEnv as public get;
30
		__setEnv as public set;
31
		__unsetEnv as public unset;
32
		__clearEnv as public clear;
33
	}
34
35
	/**
36
	 * @var string
37
	 */
38
	protected $path;
39
40
	/**
41
	 * @var string
42
	 */
43
	protected $filename;
44
45
	/**
46
	 * DotEnv constructor.
47
	 *
48
	 * @param string      $path
49
	 * @param string|null $filename
50
	 * @param bool|null   $global
51
	 */
52
	public function __construct(string $path, string $filename = null, bool $global = null){
53
		$this->path     = $path;
54
		$this->filename = $filename;
55
		$this->_global  = $global ?? true; // emulate vlucas/dotenv behaviour by default
56
	}
57
58
	/**
59
	 * @param array|null $required
60
	 *
61
	 * @return \chillerlan\Traits\DotEnv
62
	 */
63
	public function load(array $required = null):DotEnv{
64
		return $this->__loadEnv($this->path, $this->filename, true, $required, $this->_global);
65
	}
66
67
	/**
68
	 * @param string      $path
69
	 * @param string|null $filename
70
	 * @param bool|null   $overwrite
71
	 * @param array|null  $required
72
	 *
73
	 * @return \chillerlan\Traits\DotEnv
74
	 */
75
	public function addEnv(string $path, string $filename = null, bool $overwrite = null, array $required = null):DotEnv{
76
		return $this->__loadEnv($path, $filename, $overwrite, $required, $this->_global);
77
	}
78
79
}
80