Completed
Push — master ( d981b7...ea31e5 )
by Andrii
10:16
created

VhostController::getSslDir()   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 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
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 hidev\modifiers\Sudo;
15
use Yii;
16
17
/**
18
 * Goal for Nginx virtual host.
19
 */
20
class VhostController extends \hidev\controllers\CommonController
21
{
22
    /**
23
     * @var NginxController
24
     */
25
    public $nginx;
26
27
    public $ssl;
28
29
    protected $_sslDir;
30
    protected $_ip;
31
    protected $_domain;
32
    protected $_webDir;
33
    protected $_logDir;
34
    protected $_fpmSocket;
35
36
    public function actionChmodSsl()
37
    {
38
        $dir = $this->getSslDir();
39
        $this->passthru('chown', ['-R', 'www-data', $dir, Sudo::create()]);
40
        $this->passthru('chgrp', ['-R', 'www-data', $dir, Sudo::create()]);
41
        $this->passthru('chmod', ['-R', 'o-rwx',    $dir, Sudo::create()]);
42
    }
43
44
    public function renderConf()
45
    {
46
        return $this->nginx->render('default.twig', [
47
            'this' => $this,
48
        ]);
49
    }
50
51
    public function setDomain($value)
52
    {
53
        $this->_domain = $value;
54
    }
55
56
    public function getDomain()
57
    {
58
        if ($this->_domain === null || $this->_domain === 'default') {
59
            $this->_domain = $this->takePackage()->name;
60
        }
61
62
        return $this->_domain;
63
    }
64
65
    public function setIp($value)
66
    {
67
        $this->_ip = $value;
68
    }
69
70
    public function getIp()
71
    {
72
        if ($this->_ip === null) {
73
            $this->_ip = $this->findIp();
74
        }
75
76
        return $this->_ip;
77
    }
78
79
    public function findIp()
80
    {
81
        return gethostbyname($this->getDomain()) ?: '127.0.0.1';
82
    }
83
84
    public function setWebDir($value)
85
    {
86
        $this->_webDir = $value;
87
    }
88
89
    public function getWebDir()
90
    {
91
        if ($this->_webDir === null) {
92
            $this->_webDir = $this->takeGoal('start')->getRootDir() . '/web';
93
        }
94
95
        return $this->_webDir;
96
    }
97
98
    public function setLogDir($value)
99
    {
100
        $this->_logDir = $value;
101
    }
102
103
    public function getLogDir()
104
    {
105
        if ($this->_logDir === null) {
106
            $this->_logDir = $this->nginx->getLogDir();
107
        }
108
109
        return $this->_logDir;
110
    }
111
112
    public function setFpmSocket($value)
113
    {
114
        $this->_fpmSocket = $value;
115
    }
116
117
    public function getFpmSocket()
118
    {
119
        if ($this->_fpmSocket === null) {
120
            $this->_fpmSocket = $this->nginx->getFpmSocket();
121
        }
122
123
        return $this->_fpmSocket;
124
    }
125
126
    public function setSslDir($value)
127
    {
128
        $this->_sslDir = $value;
129
    }
130
131
    public function getSslDir()
132
    {
133
        return Yii::getAlias($this->_sslDir);
134
    }
135
}
136