fisharebest /
webtrees
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * webtrees: online genealogy |
||
| 5 | * Copyright (C) 2025 webtrees development team |
||
| 6 | * This program is free software: you can redistribute it and/or modify |
||
| 7 | * it under the terms of the GNU General Public License as published by |
||
| 8 | * the Free Software Foundation, either version 3 of the License, or |
||
| 9 | * (at your option) any later version. |
||
| 10 | * This program is distributed in the hope that it will be useful, |
||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 13 | * GNU General Public License for more details. |
||
| 14 | * You should have received a copy of the GNU General Public License |
||
| 15 | * along with this program. If not, see <https://www.gnu.org/licenses/>. |
||
| 16 | */ |
||
| 17 | |||
| 18 | declare(strict_types=1); |
||
| 19 | |||
| 20 | namespace Fisharebest\Webtrees\DB; |
||
| 21 | |||
| 22 | use Doctrine\DBAL\Schema\Schema as DBALSchema; |
||
| 23 | |||
| 24 | use function array_any; |
||
| 25 | use function array_filter; |
||
| 26 | use function array_map; |
||
| 27 | |||
| 28 | final readonly class Schema |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 29 | { |
||
| 30 | /** @param array<Table> $tables */ |
||
| 31 | public function __construct( |
||
| 32 | private array $tables, |
||
| 33 | ) { |
||
| 34 | } |
||
| 35 | |||
| 36 | public function dropTable(string $name): self |
||
| 37 | { |
||
| 38 | return new self( |
||
| 39 | tables: array_filter( |
||
| 40 | array: $this->tables, |
||
| 41 | callback: static fn(Table $table): bool => $table->name !== $name, |
||
| 42 | ) |
||
| 43 | ); |
||
| 44 | } |
||
| 45 | |||
| 46 | public function dropForeignKeys(): self |
||
| 47 | { |
||
| 48 | return new self( |
||
| 49 | tables: array_map( |
||
| 50 | callback: static fn(Table $table) => $table->dropForeignKeys(), |
||
| 51 | array: $this->tables, |
||
| 52 | ) |
||
| 53 | ); |
||
| 54 | } |
||
| 55 | |||
| 56 | public function hasTable(string $name): bool |
||
| 57 | { |
||
| 58 | return array_any($this->tables, static fn (Table $table): bool => $table->name === $name); |
||
| 59 | } |
||
| 60 | |||
| 61 | public function toDBAL(): DBALSchema |
||
| 62 | { |
||
| 63 | $tables = array_map( |
||
| 64 | static fn (Table $table) => $table->toDBAL(), |
||
| 65 | $this->tables, |
||
| 66 | ); |
||
| 67 | |||
| 68 | return new DBALSchema(tables: $tables); |
||
| 69 | } |
||
| 70 | } |
||
| 71 |