1 | <?php |
||
11 | final class SQL implements Base |
||
12 | { |
||
13 | protected $doctrine = null; |
||
14 | protected $dbName = null; |
||
15 | |||
16 | 3 | public function __construct($config, Connection $client) |
|
17 | { |
||
18 | 3 | $this->doctrine = $client; |
|
19 | 3 | $this->dbName = $config['db_name']; |
|
20 | 3 | } |
|
21 | |||
22 | 2 | public function getConnection() |
|
26 | |||
27 | 3 | public function create(string $collection, array $fields) |
|
33 | |||
34 | 3 | public function drop(string $collection) |
|
42 | |||
43 | public function truncate(string $collection) |
||
47 | |||
48 | public function createIndexes(string $collection, array $fields) |
||
54 | |||
55 | 3 | public function insert(string $collection, array $values) |
|
63 | |||
64 | public function update(string $collection, array $filter, array $values) |
||
68 | |||
69 | 2 | public function delete(string $collection, array $filter) |
|
74 | |||
75 | 1 | public function get(string $collection, $docId) |
|
79 | |||
80 | 1 | public function find(string $collection, ?array $filters, ?array $fields = null, ?array $sort = null, ?int $offset = 0, ?int $limit = 25) |
|
81 | { |
||
82 | 1 | $query = $this->query($collection); |
|
83 | 1 | foreach ($filters as $filter => $value) { |
|
84 | 1 | if (is_array($value)) { |
|
85 | 1 | $query->orFilters($value); |
|
86 | 1 | continue; |
|
87 | } |
||
88 | 1 | $query->andFilter($filter, $value); |
|
89 | } |
||
90 | 1 | return $query->returnFields($fields) |
|
91 | 1 | ->sortFields($sort) |
|
92 | 1 | ->offset($offset) |
|
93 | 1 | ->limit($limit) |
|
94 | 1 | ->run(); |
|
95 | } |
||
96 | |||
97 | 2 | public function query(string $collection) |
|
101 | } |
||
102 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: