1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* admin |
5
|
|
|
* |
6
|
|
|
* @category Tollwerk |
7
|
|
|
* @package Tollwerk\Admin |
8
|
|
|
* @subpackage Tollwerk\Admin\Domain\Account |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2018 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 © 2018 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\Domain\Account; |
38
|
|
|
|
39
|
|
|
use Tollwerk\Admin\Domain\Vhost\VhostInterface; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Account |
43
|
|
|
* |
44
|
|
|
* @package Tollwerk\Admin |
45
|
|
|
* @subpackage Tollwerk\Admin\Domain |
46
|
|
|
*/ |
47
|
|
|
class Account implements AccountInterface |
48
|
|
|
{ |
49
|
|
|
/** |
50
|
|
|
* Account name |
51
|
|
|
* |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
protected $name; |
55
|
|
|
/** |
56
|
|
|
* Active account |
57
|
|
|
* |
58
|
|
|
* @var boolean |
59
|
|
|
*/ |
60
|
|
|
protected $active = false; |
61
|
|
|
/** |
62
|
|
|
* Virtual hosts |
63
|
|
|
* |
64
|
|
|
* @var VhostInterface[] |
65
|
|
|
*/ |
66
|
|
|
protected $vhosts = []; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Account constructor |
70
|
|
|
* |
71
|
|
|
* @param string $name Account name |
72
|
|
|
*/ |
73
|
2 |
|
public function __construct($name) |
74
|
|
|
{ |
75
|
2 |
|
$this->name = $name; |
76
|
2 |
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Return the account name |
80
|
|
|
* |
81
|
|
|
* @return string Account name |
82
|
|
|
*/ |
83
|
1 |
|
public function getName() |
84
|
|
|
{ |
85
|
1 |
|
return $this->name; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Return whether the account is active |
90
|
|
|
* |
91
|
|
|
* @return boolean Active |
92
|
|
|
*/ |
93
|
2 |
|
public function isActive() |
94
|
|
|
{ |
95
|
2 |
|
return $this->active; |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Set whether the account is active |
100
|
|
|
* |
101
|
|
|
* @param boolean $active Active |
102
|
|
|
* @return Account Self reference |
103
|
|
|
*/ |
104
|
1 |
|
public function setActive($active) |
105
|
|
|
{ |
106
|
1 |
|
$this->active = $active; |
107
|
1 |
|
return $this; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* Return the virtual hosts |
112
|
|
|
* |
113
|
|
|
* @return VhostInterface[] Virtual hosts |
114
|
|
|
*/ |
115
|
2 |
|
public function getVhosts() |
116
|
|
|
{ |
117
|
2 |
|
return array_values($this->vhosts); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Set the virtual hosts |
122
|
|
|
* |
123
|
|
|
* @param VhostInterface[] $vhosts Virtual hosts |
124
|
|
|
* @return Account Self reference |
125
|
|
|
*/ |
126
|
1 |
|
public function setVhosts(array $vhosts) |
127
|
|
|
{ |
128
|
|
|
// Run through all virtual hosts |
129
|
1 |
|
foreach ($vhosts as $vhost) { |
130
|
1 |
|
if (!($vhost instanceof VhostInterface)) { |
131
|
1 |
|
throw new \RuntimeException('Invalid virtual host', 1475488477); |
132
|
|
|
} |
133
|
|
|
|
134
|
1 |
|
$this->vhosts[strval($vhost->getPrimaryDomain())] = $vhost; |
135
|
1 |
|
} |
136
|
1 |
|
return $this; |
137
|
|
|
} |
138
|
|
|
|
139
|
|
|
/** |
140
|
|
|
* Add a virtual host |
141
|
|
|
* |
142
|
|
|
* @param VhostInterface $vhost Virtual host |
143
|
|
|
* @return Account Self reference |
144
|
|
|
*/ |
145
|
1 |
|
public function addVirtualHost(VhostInterface $vhost) |
146
|
|
|
{ |
147
|
1 |
|
$this->vhosts[strval($vhost->getPrimaryDomain())] = $vhost; |
148
|
1 |
|
return $this; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Remove a virtual host |
153
|
|
|
* |
154
|
|
|
* @param VhostInterface $vhost Virtual host |
155
|
|
|
* @return Account Self reference |
156
|
|
|
*/ |
157
|
1 |
|
public function removeVirtualHost(VhostInterface $vhost) |
158
|
|
|
{ |
159
|
1 |
|
unset($this->vhosts[strval($vhost->getPrimaryDomain())]); |
160
|
1 |
|
return $this; |
161
|
|
|
} |
162
|
|
|
} |
163
|
|
|
|