Completed
Push — master ( 8608d4...d02428 )
by Andrii
06:44
created

HiSiteController::setDefines()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 9
ccs 7
cts 7
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 1
crap 2
1
<?php
2
/**
3
 * HiDev config for HiSite
4
 *
5
 * @link      https://github.com/hiqdev/hidev-hisite
6
 * @package   hidev-hisite
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hidev\hisite\controllers;
12
13
/**
14
 * Goal for HiSite.
15
 */
16
class HiSiteController extends \hidev\controllers\DirectoryController
17
{
18
    protected $_env;
19
    protected $_defines = [];
20
    protected $_nginx;
21
    protected $_vhost;
22
23
    public function setEnv($value)
24
    {
25
        $this->_env = $value;
26
    }
27
28 1
    public function getEnv()
29
    {
30 1
        if ($this->_env === null) {
31 1
            $this->_env = 'dev';
32 1
        }
33
34 1
        return $this->_env;
35
    }
36
37 1
    public function setDefines(array $hash)
38
    {
39 1
        $env = $this->getEnv();
40
        $defaults = [
41 1
            'YII_ENV'   => "'$env'",
42 1
            'YII_DEBUG' => $env === 'prod' ? 'false' : 'true',
43 1
        ];
44 1
        $this->_defines = array_merge($this->_defines, $defaults, $hash);
45 1
    }
46
47 1
    public function getDefines()
48
    {
49 1
        if (empty($this->_defines)) {
50 1
            $this->setDefines([]);
51 1
        }
52
53 1
        return $this->_defines;
54
    }
55
56
    public function getNginx()
57
    {
58
        if ($this->_nginx === null) {
59
            $this->_nginx = $this->takeGoal('nginx');
60
        }
61
62
        return $this->_nginx;
63
    }
64
65
    public function getVhost()
66
    {
67
        if ($this->_vhost === null) {
68
            $this->_vhost = $this->getNginx()->get('default');
69
        }
70
71
        return $this->_vhost;
72
    }
73
74
    public function setVhost(array $params)
75
    {
76
        foreach ($params as $key => $value) {
77
            $this->getVhost()->{$key} = $value;
78
        }
79
    }
80
}
81