mindplay-dk /
sql
| 1 | <?php |
||
| 2 | |||
| 3 | namespace mindplay\sql\model; |
||
| 4 | |||
| 5 | use mindplay\sql\model\query\SQLQuery; |
||
| 6 | use mindplay\sql\model\schema\Schema; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * This class implements the primary public API of the database model. |
||
| 10 | */ |
||
| 11 | abstract class Database |
||
| 12 | { |
||
| 13 | protected DatabaseContainer $container; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * The typical use-case is to omit the `$factory` argument - it exists primarily for |
||
| 17 | * mocking and dependency-injection under test. |
||
| 18 | * |
||
| 19 | * @param DatabaseContainerFactory|null $factory custom factory instance (typically omitted) |
||
| 20 | */ |
||
| 21 | 1 | public function __construct(DatabaseContainerFactory|null $factory = null) |
|
| 22 | { |
||
| 23 | 1 | if ($factory === null) { |
|
| 24 | 1 | $factory = new DatabaseContainerFactory(); |
|
| 25 | } |
||
| 26 | |||
| 27 | 1 | $this->bootstrap($factory); |
|
| 28 | |||
| 29 | 1 | $this->container = $factory->createContainer(); |
|
| 30 | } |
||
| 31 | |||
| 32 | abstract protected function bootstrap(DatabaseContainerFactory $factory): void; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param class-string $schema Schema class type-name |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 36 | */ |
||
| 37 | 1 | public function getSchema(string $schema): Schema |
|
| 38 | { |
||
| 39 | 1 | return $this->container->getSchema($schema); |
|
| 40 | } |
||
| 41 | |||
| 42 | 1 | public function sql(string $sql): SQLQuery |
|
| 43 | { |
||
| 44 | 1 | return $this->container->create(SQLQuery::class, ['sql' => $sql]); |
|
| 45 | } |
||
| 46 | } |
||
| 47 |