Completed
Push — master ( 281eb8...04fe01 )
by Sebastian
10:51
created

Dotenv::setup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
namespace phpbu\App\Adapter;
3
4
use Dotenv\Dotenv as DotenvLib;
5
use phpbu\App\Adapter;
6
use phpbu\App\Util;
7
8
/**
9
 * Dotenv Adapter
10
 *
11
 * @package    phpbu
12
 * @subpackage App
13
 * @author     Sebastian Feldmann <[email protected]>
14
 * @copyright  Sebastian Feldmann <[email protected]>
15
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
16
 * @link       http://phpbu.de/
17
 * @since      Class available since Release 4.0.0
18
 */
19
class Dotenv implements Adapter
20
{
21
    /**
22
     * Path to the .env file
23
     *
24
     * @var string
25
     */
26
    private $file;
27
28
    /**
29
     * Actual dot env reader
30
     *
31
     * @var \Dotenv\Dotenv
32
     */
33
    private $dotenv;
34
35
    /**
36
     * Setup the adapter.
37
     *
38
     * @param  array $conf
39
     * @return void
40
     */
41
    public function setup(array $conf)
42
    {
43
        $this->file   = Util\Arr::getValue($conf, 'file', '.env');
44
        $this->dotenv = new DotenvLib(dirname($this->file), basename($this->file));
45
        $this->dotenv->load();
46
    }
47
48
    /**
49
     * Return a value for a given path.
50
     *
51
     * @param  string $path
52
     * @return string
53
     */
54
    public function getValue($path)
55
    {
56
        return getenv($path);
57
    }
58
}
59