Completed
Push — master ( 79ff26...9e9048 )
by Niels
02:04
created

BaseContext::invokeApiPost()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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\Context;
12
13
use Omines\DirectAdmin\DirectAdmin;
14
15
/**
16
 * Encapsulates a contextual connection to a DirectAdmin server.
17
 *
18
 * @author Niels Keurentjes <[email protected]>
19
 */
20
abstract class BaseContext
21
{
22
    /** @var DirectAdmin */
23
    private $connection;
24
25
    /**
26
     * Constructs the object.
27
     *
28
     * @param DirectAdmin $connection A prepared connection
29
     */
30
    public function __construct(DirectAdmin $connection)
31
    {
32
        $this->connection = $connection;
33
    }
34
35
    /**
36
     * Returns the internal connection wrapper.
37
     *
38
     * @return DirectAdmin
39
     */
40
    protected function getConnection()
41
    {
42
        return $this->connection;
43
    }
44
45
    /**
46
     * Invokes the DirectAdmin API via HTTP GET.
47
     *
48
     * @param string $command DirectAdmin API command to invoke
49
     * @param array $query Optional query parameters
50
     * @return array The parsed and validated response
51
     */
52
    public function invokeApiGet($command, $query = [])
53
    {
54
        return $this->connection->invokeApi('GET', $command, ['query' => $query]);
55
    }
56
57
    /**
58
     * Invokes the DirectAdmin API via HTTP POST.
59
     *
60
     * @param string $command DirectAdmin API command to invoke
61
     * @param array $postParameters Optional form parameters
62
     * @return array The parsed and validated response
63
     */
64
    public function invokeApiPost($command, $postParameters = [])
65
    {
66
        return $this->connection->invokeApi('POST', $command, ['form_params' => $postParameters]);
67
    }
68
}
69