Completed
Push — master ( c1df42...1ce5d6 )
by Andrii
01:51
created

VhostController::setFpmSocket()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * HiDev Nginx plugin
5
 *
6
 * @link      https://github.com/hiqdev/hidev-nginx
7
 * @package   hidev-nginx
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hidev\nginx\controllers;
13
14
use Yii;
15
16
/**
17
 * Goal for Nginx virtual host.
18
 */
19
class VhostController extends \hidev\controllers\CommonController
20
{
21
    /**
22
     * @var NginxController
23
     */
24
    public $nginx;
25
26
    public $ssl;
27
28
    protected $_sslPath;
29
    protected $_ip;
30
    protected $_domain;
31
    protected $_webDir;
32
    protected $_logDir;
33
    protected $_fpmSocket;
34
35
    public function renderConf()
36
    {
37
        return $this->nginx->render('default.twig', [
38
            'this' => $this,
39
        ]);
40
    }
41
42
    public function setDomain($value)
43
    {
44
        $this->_domain = $value;
45
    }
46
47
    public function getDomain()
48
    {
49
        if ($this->_domain === null || $this->_domain === 'default') {
50
            $this->_domain = $this->takePackage()->name;
51
        }
52
53
        return $this->_domain;
54
    }
55
56
    public function setIp($value)
57
    {
58
        $this->_ip = $value;
59
    }
60
61
    public function getIp()
62
    {
63
        if ($this->_ip === null) {
64
            $this->_ip = $this->findIp();
65
        }
66
67
        return $this->_ip;
68
    }
69
70
    public function findIp()
71
    {
72
        return gethostbyname($this->getDomain()) ?: '127.0.0.1';
73
    }
74
75
    public function setWebDir($value)
76
    {
77
        $this->_webDir = $value;
78
    }
79
80
    public function getWebDir()
81
    {
82
        if ($this->_webDir === null) {
83
            $this->_webDir = $this->takeGoal('start')->getRootDir() . '/web';
84
        }
85
86
        return $this->_webDir;
87
    }
88
89
    public function setLogDir($value)
90
    {
91
        $this->_logDir = $value;
92
    }
93
94
    public function getLogDir()
95
    {
96
        if ($this->_logDir === null) {
97
            $this->_logDir = $this->nginx->getLogDir();
98
        }
99
100
        return $this->_logDir;
101
    }
102
103
    public function setFpmSocket($value)
104
    {
105
        $this->_fpmSocket = $value;
106
    }
107
108
    public function getFpmSocket()
109
    {
110
        if ($this->_fpmSocket === null) {
111
            $this->_fpmSocket = $this->nginx->getFpmSocket();
112
        }
113
114
        return $this->_fpmSocket;
115
    }
116
117
    public function setSslPath($value)
118
    {
119
        $this->_sslPath = $value;
120
    }
121
122
    public function getSslPath()
123
    {
124
        return Yii::getAlias($this->_sslPath);
125
    }
126
}
127