1 | <?php |
||
2 | |||
3 | namespace Bdf\Prime\Connection; |
||
4 | |||
5 | use Bdf\Prime\Connection\Result\ResultSetInterface; |
||
6 | use Bdf\Prime\Exception\PrimeException; |
||
7 | use Bdf\Prime\Exception\QueryBuildingException; |
||
8 | use Bdf\Prime\Exception\QueryExecutionException; |
||
9 | use Bdf\Prime\Platform\PlatformInterface; |
||
10 | use Bdf\Prime\Query\CommandInterface; |
||
11 | use Bdf\Prime\Query\Compiler\Preprocessor\PreprocessorInterface; |
||
12 | use Bdf\Prime\Query\Contract\Compilable; |
||
13 | use Bdf\Prime\Query\Factory\QueryFactoryInterface; |
||
14 | use Bdf\Prime\Query\QueryInterface; |
||
15 | use Bdf\Prime\Query\ReadCommandInterface; |
||
16 | use Bdf\Prime\Schema\Manager\DatabaseManagerInterface; |
||
17 | use Bdf\Prime\Schema\SchemaManagerInterface; |
||
18 | use Bdf\Prime\Types\TypeInterface; |
||
19 | use Doctrine\Common\EventManager; |
||
20 | |||
21 | /** |
||
22 | * Base connection type |
||
23 | * |
||
24 | * Allows creating and executing queries, and handle a platform |
||
25 | */ |
||
26 | interface ConnectionInterface |
||
27 | { |
||
28 | /** |
||
29 | * Set the connection name |
||
30 | * |
||
31 | * @param string $name |
||
32 | * |
||
33 | * @return $this |
||
34 | */ |
||
35 | public function setName(string $name); |
||
36 | |||
37 | /** |
||
38 | * Get the connection name |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | public function getName(): string; |
||
43 | |||
44 | /** |
||
45 | * Gets the SchemaManager. |
||
46 | * |
||
47 | * @return DatabaseManagerInterface |
||
48 | * @throws PrimeException |
||
49 | */ |
||
50 | public function schema(): DatabaseManagerInterface; |
||
51 | |||
52 | /** |
||
53 | * Transform database value to PHP value |
||
54 | * |
||
55 | * @param mixed $value |
||
56 | * @param string|TypeInterface $type |
||
57 | * |
||
58 | * @param array $fieldOptions |
||
59 | * @return mixed |
||
60 | * |
||
61 | * @throws PrimeException When cannot convert value |
||
62 | */ |
||
63 | public function fromDatabase($value, $type, array $fieldOptions = []); |
||
64 | |||
65 | /** |
||
66 | * Transform PHP value to database value |
||
67 | * |
||
68 | * @param mixed $value |
||
69 | * @param null|string|TypeInterface $type |
||
70 | * |
||
71 | * @return mixed |
||
72 | * |
||
73 | * @throws PrimeException When cannot convert value |
||
74 | */ |
||
75 | public function toDatabase($value, $type = null); |
||
76 | |||
77 | /** |
||
78 | * Get a query builder |
||
79 | * |
||
80 | * @param PreprocessorInterface|null $preprocessor The compiler preprocessor to use |
||
81 | * |
||
82 | * @return ReadCommandInterface |
||
83 | */ |
||
84 | public function builder(PreprocessorInterface $preprocessor = null): ReadCommandInterface; |
||
85 | |||
86 | /** |
||
87 | * Make a new query |
||
88 | * |
||
89 | * @param class-string<Q> $query The query name, or class name |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
![]() |
|||
90 | * @param PreprocessorInterface|null $preprocessor The compiler preprocessor to use |
||
91 | * |
||
92 | * @return Q |
||
93 | * |
||
94 | * @template Q as CommandInterface |
||
95 | */ |
||
96 | public function make(string $query, PreprocessorInterface $preprocessor = null): CommandInterface; |
||
97 | |||
98 | /** |
||
99 | * Get the query factory for this connection |
||
100 | * |
||
101 | * @return QueryFactoryInterface |
||
102 | */ |
||
103 | public function factory(): QueryFactoryInterface; |
||
104 | |||
105 | /** |
||
106 | * Get a select query builder from table |
||
107 | * |
||
108 | * @param string|QueryInterface $table The "from" clause. Can be a table name or an embedded query |
||
109 | * @param string|null $alias The clause alias |
||
110 | * |
||
111 | * @return ReadCommandInterface |
||
112 | */ |
||
113 | public function from($table, ?string $alias = null): ReadCommandInterface; |
||
114 | |||
115 | /** |
||
116 | * Executes a raw select query and returns array of object |
||
117 | * |
||
118 | * @param mixed $query The raw query to execute |
||
119 | * @param array $bindings The query bindings |
||
120 | * |
||
121 | * @return ResultSetInterface<\stdClass> The database result, in object form |
||
122 | * @throws PrimeException When select fail |
||
123 | */ |
||
124 | public function select($query, array $bindings = []): ResultSetInterface; |
||
125 | |||
126 | /** |
||
127 | * Execute the query and get the result. |
||
128 | * The result may differ by the query type |
||
129 | * |
||
130 | * @param Compilable $query Query to execute |
||
131 | * |
||
132 | * @return ResultSetInterface<array<string, mixed>> |
||
133 | * |
||
134 | * @see Compilable::type() The query type |
||
135 | * |
||
136 | * @throws QueryExecutionException When query execution fail |
||
137 | * @throws QueryBuildingException When query compilation fail |
||
138 | * @throws PrimeException When execution fail |
||
139 | */ |
||
140 | public function execute(Compilable $query): ResultSetInterface; |
||
141 | |||
142 | /** |
||
143 | * Gets the name of the database this Connection is connected to. |
||
144 | * |
||
145 | * @return string|null |
||
146 | */ |
||
147 | public function getDatabase(): ?string; |
||
148 | |||
149 | /** |
||
150 | * Get the platform instance |
||
151 | * |
||
152 | * @return PlatformInterface |
||
153 | * @throws PrimeException |
||
154 | */ |
||
155 | public function platform(): PlatformInterface; |
||
156 | |||
157 | /** |
||
158 | * Gets the EventManager used by the Connection. |
||
159 | * |
||
160 | * @return EventManager |
||
161 | * |
||
162 | * @todo Ne pas utiliser l'event manager de doctrine ? |
||
163 | * C'est actuellement le plus simple et léger, mais ajoute une dépendence forte à Doctrine |
||
164 | * |
||
165 | * @internal |
||
166 | */ |
||
167 | public function getEventManager(); |
||
168 | |||
169 | /** |
||
170 | * Closes the connection and trigger "onConnectionClosed" event |
||
171 | * |
||
172 | * @return void |
||
173 | */ |
||
174 | public function close(): void; |
||
175 | } |
||
176 |