1 <?php
 2 
 3  4  5  6  7  8  9 
10 
11 namespace Omines\DirectAdmin\Objects\Database;
12 
13 use Omines\DirectAdmin\Objects\Database;
14 use Omines\DirectAdmin\Objects\BaseObject;
15 
16 17 18 
19 class AccessHost extends BaseObject
20 {
21     
22     protected $database;
23 
24     25 26 27 
28     public function __construct($host, Database $database)
29     {
30         parent::__construct($host, $database->getContext());
31         $this->database = $database;
32     }
33 
34     35 36 37 38 
39     public static function create(Database $database, $host)
40     {
41         $database->getContext()->invokeApiPost('DATABASES', [
42             'action' => 'accesshosts',
43             'create' => 'yes',
44             'db' => $database->getDatabaseName(),
45             'host' => $host,
46         ]);
47         return new self($host, $database);
48     }
49 
50     51 52 
53     public function delete()
54     {
55         $this->getContext()->invokeApiPost('DATABASES', [
56             'action' => 'accesshosts',
57             'delete' => 'yes',
58             'db' => $this->database->getDatabaseName(),
59             'select0' => $this->getName(),
60         ]);
61         $this->database->clearCache();
62     }
63 
64     65 66 
67     public function getHost()
68     {
69         return $this->getName();
70     }
71 
72     73 74 
75     public function __toString()
76     {
77         return $this->getHost();
78     }
79 }
80