Completed
Push — master ( 8eb78c...be9ae1 )
by Niels
8s
created

AccessHost::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
/**
3
 * DirectAdmin
4
 * (c) Omines Internetbureau B.V.
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace Omines\DirectAdmin\Objects\Database;
11
12
use Omines\DirectAdmin\Objects\Database;
13
use Omines\DirectAdmin\Objects\Object;
14
15
class AccessHost extends Object
16
{
17
    /** @var Database $database */
18
    protected $database;
19
20
    /**
21
     * @param string   $host
22
     * @param Database $database
23
     */
24
    public function __construct($host, Database $database)
25
    {
26
        parent::__construct($host, $database->getContext());
27
        $this->database = $database;
28
    }
29
30
    /**
31
     * @param Database $database
32
     * @param string   $host
33
     * @return AccessHost
34
     */
35
    public static function create(Database $database, $host)
36
    {
37
        $database->getContext()->invokePost('DATABASES', [
38
            'action' => 'accesshosts',
39
            'create' => 'yes',
40
            'db' => $database->getDatabaseName(),
41
            'host' => $host,
42
        ]);
43
        return new self($host, $database);
44
    }
45
46
    /**
47
     * Deletes the access host
48
     */
49
    public function delete()
50
    {
51
        $this->getContext()->invokePost('DATABASES', [
52
            'action' => 'accesshosts',
53
            'delete' => 'yes',
54
            'db' => $this->database->getDatabaseName(),
55
            'select0' => $this->getName(),
56
        ]);
57
    }
58
59
    /**
60
     * @return string
61
     */
62
    public function getHost()
63
    {
64
        return $this->getName();
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function __toString()
71
    {
72
        return $this->getHost();
73
    }
74
}
75