1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Hgraca\Phorensic\SharedKernel\Port\Database\Adapter\MicroDbal; |
4
|
|
|
|
5
|
|
|
use Hgraca\MicroDbal\CrudClientInterface; |
6
|
|
|
use Hgraca\MicroDbal\RawClientInterface; |
7
|
|
|
use Hgraca\Phorensic\SharedKernel\Port\Database\DatabaseClientInterface; |
8
|
|
|
|
9
|
|
|
final class MicroDbalAdapter implements DatabaseClientInterface |
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var CrudClientInterface |
14
|
|
|
*/ |
15
|
|
|
private $crudClient; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var RawClientInterface |
19
|
|
|
*/ |
20
|
|
|
private $rawClient; |
21
|
|
|
|
22
|
|
|
public function __construct(CrudClientInterface $crudClient, RawClientInterface $rawClient) |
23
|
|
|
{ |
24
|
|
|
$this->crudClient = $crudClient; |
25
|
|
|
$this->rawClient = $rawClient; |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Executes a query for data. |
30
|
|
|
* |
31
|
|
|
* @param string $queryString The native query string, with place holders for the data bindings |
32
|
|
|
* @param array $bindingsList The data bindings to be injected in the query, escaped and formatted in the correct |
33
|
|
|
* data type, according to the native data engine being used. |
34
|
|
|
* Ie: ['bindingName' => 'value', 'otherBindingName' => 1, ...] |
35
|
|
|
*/ |
36
|
|
|
public function executeQuery(string $queryString, array $bindingsList = []): array |
37
|
|
|
{ |
38
|
|
|
return $this->rawClient->executeQuery($queryString, $bindingsList); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function create(string $table, array $data) |
42
|
|
|
{ |
43
|
|
|
$this->crudClient->create($table, $data); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function read(string $table, array $filter = [], array $orderBy = [], int $limit = null, int $offset = 1): array |
47
|
|
|
{ |
48
|
|
|
return $this->crudClient->read($table, $filter, $orderBy, $limit, $offset); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function update(string $table, array $data, array $filter = []) |
52
|
|
|
{ |
53
|
|
|
$this->crudClient->update($table, $data, $filter); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|