Completed
Push — master ( ee041c...22b621 )
by Joschi
04:52
created

Vhost::releasePrimaryDomain()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
c 0
b 0
f 0
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * admin
5
 *
6
 * @category    Tollwerk
7
 * @package     Tollwerk\Admin
8
 * @subpackage  Tollwerk\Admin\Infrastructure\Model
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Tollwerk\Admin\Infrastructure\Model;
38
39
use Tollwerk\Admin\Infrastructure\App;
40
41
/**
42
 * Virtual host model
43
 *
44
 * @package Tollwerk\Admin
45
 * @subpackage Tollwerk\Admin\Infrastructure
46
 * @Entity
47
 * @HasLifecycleCallbacks
48
 * @Table(name="vhost",uniqueConstraints={@UniqueConstraint(name="docroot_idx", columns={"account_id", "docroot"})})
49
 */
50
class Vhost
51
{
52
    /**
53
     * Virtual host ID
54
     *
55
     * @var integer
56
     * @Id @Column(type="integer")
57
     * @GeneratedValue
58
     */
59
    protected $id;
60
    /**
61
     * Active
62
     *
63
     * @var boolean
64
     * @Column(type="boolean")
65
     */
66
    protected $active;
67
    /**
68
     * Account this domain is belonging to
69
     *
70
     * @var Account
71
     * @ManyToOne(targetEntity="Tollwerk\Admin\Infrastructure\Model\Account", inversedBy="vhosts")
72
     * @JoinColumn(name="account_id", referencedColumnName="id", onDelete="CASCADE")
73
     */
74
    protected $account;
75
    /**
76
     * Virtual host type
77
     *
78
     * @var string
79
     * @Column(type="enumvhosttype")
80
     */
81
    protected $type;
82
    /**
83
     * Primary domain of this virtual host
84
     *
85
     * @var Domain
86
     */
87
    protected $primarydomain;
88
    /**
89
     * List of all associated domains
90
     *
91
     * @var Domain[]
92
     * @OneToMany(targetEntity="Tollwerk\Admin\Infrastructure\Model\Domain", mappedBy="vhost")
93
     */
94
    protected $domains;
95
    /**
96
     * Document root directory
97
     *
98
     * @var string
99
     * @Column(length=128,unique=true)
100
     */
101
    protected $docroot;
102
    /**
103
     * HTTP Port
104
     *
105
     * @var int|null
106
     * @Column(type="integer", nullable=true, options={"unsigned":true, "default":80})
107
     */
108
    protected $httpport = 80;
109
    /**
110
     * HTTPS Port
111
     *
112
     * @var int|null
113
     * @Column(type="integer", nullable=true, options={"unsigned":true, "default":443})
114
     */
115
    protected $httpsport = 443;
116
    /**
117
     * Supported PHP version
118
     *
119
     * @var float|null
120
     * @Column(type="decimal",precision=2,scale=1,nullable=true)
121
     */
122
    protected $php = null;
123
    /**
124
     * Redirect URL
125
     *
126
     * @var string
127
     * @Column(length=128, nullable=true)
128
     */
129
    protected $redirecturl = null;
130
    /**
131
     * Redirect status
132
     *
133
     * @var int
134
     * @Column(type="integer", nullable=false, options={"unsigned":true, "default":301})
135
     */
136
    protected $redirectstatus = \Tollwerk\Admin\Domain\Vhost\Vhost::REDIRECT_DEFAULT_STATUS;
137
138
    /**
139
     * Return the vhost ID
140
     *
141
     * @return int Vhost ID
142
     */
143
    public function getId()
144
    {
145
        return $this->id;
146
    }
147
148
    /**
149
     * Set the vhost ID
150
     *
151
     * @param int $id Vhost ID
152
     * @return Vhost
153
     */
154
    public function setId($id)
155
    {
156
        $this->id = $id;
157
        return $this;
158
    }
159
160
    /**
161
     * Set whether this is an active vhost
162
     *
163
     * @param boolean $active Active vhost
164
     * @return Vhost
165
     */
166
    public function setActive($active)
167
    {
168
        $this->active = $active;
169
        return $this;
170
    }
171
172
    /**
173
     * Return whether the vhost is ative
174
     *
175
     * @return boolean Active vhost
176
     */
177
    public function isActive()
178
    {
179
        return $this->active;
180
    }
181
182
    /**
183
     * Return the account this virtual host is belonging to
184
     *
185
     * @return Account Account
186
     */
187
    public function getAccount()
188
    {
189
        return $this->account;
190
    }
191
192
    /**
193
     * Set the account this virtual host is belonging tp
194
     *
195
     * @param Account $account Account
196
     * @return Vhost Self reference
197
     */
198
    public function setAccount($account)
199
    {
200
        $this->account = $account;
201
        return $this;
202
    }
203
204
    /**
205
     * Return the virtual host type
206
     *
207
     * @return string Virtual host type
208
     */
209
    public function getType()
210
    {
211
        return $this->type;
212
    }
213
214
    /**
215
     * Set the virtual host type
216
     *
217
     * @param string $type Virtual host type
218
     * @return Vhost Self reference
219
     */
220
    public function setType($type)
221
    {
222
        $this->type = $type;
223
        return $this;
224
    }
225
226
    /**
227
     * Return the associated domains
228
     *
229
     * @return Domain[] Associated domains
230
     */
231
    public function getDomains()
232
    {
233
        return $this->domains;
234
    }
235
236
    /**
237
     * Set the associated domains
238
     *
239
     * @param Domain[] $domains Associated domains
240
     * @return Vhost Self reference
241
     */
242
    public function setDomains($domains)
243
    {
244
        $this->domains = $domains;
245
        return $this;
246
    }
247
248
    /**
249
     * Return the primary domain of this virtual host
250
     *
251
     * @return Domain Primary domain
252
     */
253
    public function getPrimarydomain()
254
    {
255
        if ($this->primarydomain === null) {
256
            $entityManager = App::getEntityManager();
257
            $domainRepository = $entityManager->getRepository(Domain::class);
258
            $this->primarydomain = $domainRepository->findOneBy(['vhost' => $this->getId(), 'primarydomain' => 1]);
259
        }
260
261
        return $this->primarydomain;
262
    }
263
264
    /**
265
     * Set the primary domain of this virtual host
266
     *
267
     * @param Domain $primarydomain Primary domain
268
     * @return Vhost Self reference
269
     */
270
    public function setPrimarydomain($primarydomain)
271
    {
272
        $this->primarydomain = $primarydomain;
273
        return $this;
274
    }
275
276
    /**
277
     * Return the document root
278
     *
279
     * @return string Document root
280
     */
281
    public function getDocroot()
282
    {
283
        return $this->docroot;
284
    }
285
286
    /**
287
     * Set the document root
288
     *
289
     * @param string $docroot Document root
290
     * @return Vhost Self reference
291
     */
292
    public function setDocroot($docroot)
293
    {
294
        $this->docroot = $docroot;
295
        return $this;
296
    }
297
298
    /**
299
     * Return the HTTP port
300
     *
301
     * @return int|null HTTP port
302
     */
303
    public function getHttpport()
304
    {
305
        return $this->httpport;
306
    }
307
308
    /**
309
     * Set the HTTP port
310
     *
311
     * @param int|null $httpport HTTP port
312
     * @return Vhost Self reference
313
     */
314
    public function setHttpport($httpport)
315
    {
316
        $this->httpport = $httpport;
317
        return $this;
318
    }
319
320
    /**
321
     * Return the HTTPS port
322
     *
323
     * @return int|null HTTPS port
324
     */
325
    public function getHttpsport()
326
    {
327
        return $this->httpsport;
328
    }
329
330
    /**
331
     * Set the HTTPS port
332
     *
333
     * @param int|null $httpsport HTTPS port
334
     * @return Vhost
335
     */
336
    public function setHttpsport($httpsport)
337
    {
338
        $this->httpsport = $httpsport;
339
        return $this;
340
    }
341
342
    /**
343
     * Return the supported PHP version
344
     *
345
     * @return float|null Supported PHP version
346
     */
347
    public function getPhp()
348
    {
349
        return $this->php;
350
    }
351
352
    /**
353
     * Set the supported PHP version
354
     *
355
     * @param float|null $php Supported PHP version
356
     * @return Vhost Self reference
357
     */
358
    public function setPhp($php)
359
    {
360
        $this->php = $php;
361
        return $this;
362
    }
363
364
    /**
365
     * Return the redirect URL
366
     *
367
     * @return string Redirect URL
368
     */
369
    public function getRedirecturl()
370
    {
371
        return $this->redirecturl;
372
    }
373
374
    /**
375
     * Set the redirect URL
376
     *
377
     * @param string $redirecturl Redirect URL
378
     * @return Vhost Self reference
379
     */
380
    public function setRedirecturl($redirecturl)
381
    {
382
        $this->redirecturl = $redirecturl;
383
        return $this;
384
    }
385
386
    /**
387
     * Return the redirect status
388
     *
389
     * @return int Redirect status
390
     */
391
    public function getRedirectstatus()
392
    {
393
        return $this->redirectstatus;
394
    }
395
396
    /**
397
     * Set the redirect status
398
     *
399
     * @param int $redirectstatus Redirect status
400
     * @return Vhost Self reference
401
     */
402
    public function setRedirectstatus($redirectstatus)
403
    {
404
        $this->redirectstatus = $redirectstatus;
405
        return $this;
406
    }
407
408
    /**
409
     * Release the primary domain on deletion of this virtual host
410
     *
411
     * @PreRemove
412
     */
413
    public function releasePrimaryDomain() {
414
        $this->getPrimarydomain()->setPrimarydomain(false);
415
        App::getEntityManager()->persist($this->getPrimarydomain());
416
        App::getEntityManager()->flush();
417
    }
418
}
419