|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Hgraca\MicroDbal\Crud; |
|
4
|
|
|
|
|
5
|
|
|
use Hgraca\MicroDbal\CrudClientInterface; |
|
6
|
|
|
use Hgraca\MicroDbal\RawClientInterface; |
|
7
|
|
|
|
|
8
|
|
|
final class CrudClient implements CrudClientInterface |
|
9
|
|
|
{ |
|
10
|
|
|
/** |
|
11
|
|
|
* @var RawClientInterface |
|
12
|
|
|
*/ |
|
13
|
|
|
private $client; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* @var CrudQueryBuilderInterface |
|
17
|
|
|
*/ |
|
18
|
|
|
private $crudQueryBuilder; |
|
19
|
|
|
|
|
20
|
10 |
|
public function __construct(RawClientInterface $client, CrudQueryBuilderInterface $crudQueryBuilder) |
|
21
|
|
|
{ |
|
22
|
10 |
|
$this->client = $client; |
|
23
|
10 |
|
$this->crudQueryBuilder = $crudQueryBuilder; |
|
24
|
10 |
|
} |
|
25
|
|
|
|
|
26
|
2 |
|
public function create(string $table, array $data) |
|
27
|
|
|
{ |
|
28
|
2 |
|
list($queryString, $dataBindingsList) = $this->crudQueryBuilder->buildCreateQuery($table, $data); |
|
29
|
2 |
|
$this->client->executeCommand($queryString, $dataBindingsList); |
|
30
|
2 |
|
} |
|
31
|
|
|
|
|
32
|
10 |
|
public function read( |
|
33
|
|
|
string $table, |
|
34
|
|
|
array $filter = [], |
|
35
|
|
|
array $orderBy = [], |
|
36
|
|
|
int $limit = null, |
|
37
|
|
|
int $offset = 1 |
|
38
|
|
|
): array { |
|
39
|
10 |
|
list($queryString, $filterBindingsList) = $this->crudQueryBuilder |
|
40
|
10 |
|
->buildReadQuery($table, $filter, $orderBy, $limit, $offset); |
|
41
|
10 |
|
return $this->client->executeQuery($queryString, $filterBindingsList); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
public function update(string $table, array $data, array $filter = []) |
|
45
|
|
|
{ |
|
46
|
1 |
|
list($queryString, $bindingsList) = $this->crudQueryBuilder->buildUpdateQuery($table, $data, $filter); |
|
47
|
1 |
|
$this->client->executeCommand($queryString, $bindingsList); |
|
48
|
1 |
|
} |
|
49
|
|
|
|
|
50
|
2 |
|
public function delete(string $table, array $filter = []) |
|
51
|
|
|
{ |
|
52
|
2 |
|
list($queryString, $filterBindingsList) = $this->crudQueryBuilder->buildDeleteQuery($table, $filter); |
|
53
|
2 |
|
$this->client->executeCommand($queryString, $filterBindingsList); |
|
54
|
2 |
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|