|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* DirectAdmin API Client |
|
5
|
|
|
* (c) Omines Internetbureau B.V. - https://omines.nl/ |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Omines\DirectAdmin\Objects\Domains; |
|
12
|
|
|
|
|
13
|
|
|
use Omines\DirectAdmin\Objects\Domain; |
|
14
|
|
|
use Omines\DirectAdmin\Objects\DomainObject; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Subdomain. |
|
18
|
|
|
* |
|
19
|
|
|
* @author Niels Keurentjes <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class Subdomain extends DomainObject |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* Construct the object. |
|
25
|
|
|
* |
|
26
|
|
|
* @param string $prefix The domain name |
|
27
|
|
|
* @param Domain $domain The containing domain |
|
28
|
|
|
*/ |
|
29
|
|
|
public function __construct($prefix, Domain $domain) |
|
30
|
|
|
{ |
|
31
|
|
|
parent::__construct($prefix, $domain); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Creates a new subdomain. |
|
36
|
|
|
* |
|
37
|
|
|
* @param Domain $domain Parent domain |
|
38
|
|
|
* @param string $prefix Prefix of the subdomain |
|
39
|
|
|
* @return Subdomain The newly created object |
|
40
|
|
|
*/ |
|
41
|
|
|
public static function create(Domain $domain, $prefix) |
|
42
|
|
|
{ |
|
43
|
|
|
$domain->invokePost('SUBDOMAIN', 'create', ['subdomain' => $prefix]); |
|
44
|
|
|
return new self($prefix, $domain); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Deletes the subdomain. |
|
49
|
|
|
* |
|
50
|
|
|
* @param bool $deleteContents Whether to delete all directory contents as well |
|
51
|
|
|
*/ |
|
52
|
|
|
public function delete($deleteContents = true) |
|
53
|
|
|
{ |
|
54
|
|
|
$this->invokePost('SUBDOMAIN', 'delete', [ |
|
55
|
|
|
'select0' => $this->getPrefix(), |
|
56
|
|
|
'contents' => ($deleteContents ? 'yes' : 'no'), |
|
57
|
|
|
]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Returns the full domain name for the subdomain. |
|
62
|
|
|
* |
|
63
|
|
|
* @return string |
|
64
|
|
|
*/ |
|
65
|
|
|
public function getDomainName() |
|
66
|
|
|
{ |
|
67
|
|
|
return $this->getPrefix() . '.' . parent::getDomainName(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Returns the full domain name for the subdomain. |
|
72
|
|
|
* |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
|
|
public function getBaseDomainName() |
|
76
|
|
|
{ |
|
77
|
|
|
return parent::getDomainName(); |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Returns the prefix of the subdomain. |
|
82
|
|
|
* |
|
83
|
|
|
* @return string |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getPrefix() |
|
86
|
|
|
{ |
|
87
|
|
|
return $this->getName(); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Allows the class to be used as a string representing the full domain name. |
|
92
|
|
|
* |
|
93
|
|
|
* @return string |
|
94
|
|
|
*/ |
|
95
|
|
|
public function __toString() |
|
96
|
|
|
{ |
|
97
|
|
|
return $this->getDomainName(); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|