| Total Complexity | 10 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Coverage | 73.91% |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 7 | final class ConnectionManager |
||
| 8 | { |
||
| 9 | /** @var Connection[] */ |
||
| 10 | private static $connections = []; |
||
| 11 | |||
| 12 | private const DEFAULT_NAME = 'default'; |
||
| 13 | |||
| 14 | 49 | public static function release(): void |
|
| 15 | { |
||
| 16 | 49 | foreach (self::$connections as $connection) { |
|
| 17 | 48 | $connection->close(); |
|
| 18 | } |
||
| 19 | |||
| 20 | 49 | self::$connections = []; |
|
| 21 | 49 | } |
|
| 22 | |||
| 23 | 49 | public static function register(string $name, Connection $connection): void |
|
| 24 | { |
||
| 25 | 49 | if (self::has($name)) { |
|
| 26 | throw StorageException::forAlreadyExistingConnection($name); |
||
| 27 | } |
||
| 28 | |||
| 29 | 49 | self::$connections[$name] = $connection; |
|
| 30 | 49 | } |
|
| 31 | |||
| 32 | 49 | public static function registerDefault(Connection $connection): void |
|
| 35 | 49 | } |
|
| 36 | |||
| 37 | 49 | public static function has(string $name): bool |
|
| 38 | { |
||
| 39 | 49 | return isset(self::$connections[$name]); |
|
| 40 | } |
||
| 41 | |||
| 42 | public static function hasDefault(): bool |
||
| 43 | { |
||
| 44 | return self::has(self::DEFAULT_NAME); |
||
| 45 | } |
||
| 46 | |||
| 47 | public static function getDefault(): Connection |
||
| 50 | } |
||
| 51 | |||
| 52 | 22 | public static function get(string $name): Connection |
|
| 59 | } |
||
| 60 | } |
||
| 61 |