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\Users; |
12
|
|
|
|
13
|
|
|
use Omines\DirectAdmin\Context\AdminContext; |
14
|
|
|
use Omines\DirectAdmin\Context\ResellerContext; |
15
|
|
|
use Omines\DirectAdmin\Context\UserContext; |
16
|
|
|
use Omines\DirectAdmin\DirectAdminException; |
17
|
|
|
use Omines\DirectAdmin\Objects\BaseObject; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Reseller. |
21
|
|
|
* |
22
|
|
|
* @author Niels Keurentjes <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class Reseller extends User |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* {@inheritdoc} |
28
|
|
|
*/ |
29
|
|
|
public function __construct($name, UserContext $context, $config = null) |
30
|
|
|
{ |
31
|
|
|
parent::__construct($name, $context, $config); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param string $username |
36
|
|
|
* @return null|User |
37
|
|
|
*/ |
38
|
|
|
public function getUser($username) |
39
|
|
|
{ |
40
|
|
|
$users = $this->getUsers(); |
41
|
|
|
return isset($users[$username]) ? $users[$username] : null; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @return User[] |
46
|
|
|
*/ |
47
|
|
|
public function getUsers() |
48
|
|
|
{ |
49
|
|
|
return BaseObject::toObjectArray($this->getContext()->invokeApiGet('SHOW_USERS', ['reseller' => $this->getUsername()]), |
50
|
|
|
User::class, $this->getContext()); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @return ResellerContext |
55
|
|
|
*/ |
56
|
|
View Code Duplication |
public function impersonate() |
|
|
|
|
57
|
|
|
{ |
58
|
|
|
/** @var AdminContext $context */ |
59
|
|
|
if (!($context = $this->getContext()) instanceof AdminContext) { |
60
|
|
|
throw new DirectAdminException('You need to be an admin to impersonate a reseller'); |
61
|
|
|
} |
62
|
|
|
return $context->impersonateReseller($this->getUsername()); |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.