| 1 |
<?php |
| 2 |
/** |
| 3 |
* Registers database related functionality in the container. |
| 4 |
* |
| 5 |
* @package SolidWP\Performance |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace SolidWP\Performance\Database; |
| 11 |
|
| 12 |
use SolidWP\Performance\Contracts\Service_Provider; |
| 13 |
use SolidWP\Performance\Lock\Tables\Cache_Lock; |
| 14 |
use SolidWP\Performance\Psr\Log\LoggerInterface; |
| 15 |
use SolidWP\Performance\StellarWP\DB\Database\Exceptions\DatabaseQueryException; |
| 16 |
use SolidWP\Performance\StellarWP\DB\DB; |
| 17 |
use SolidWP\Performance\StellarWP\Schema\Config; |
| 18 |
use SolidWP\Performance\StellarWP\Schema\Register; |
| 19 |
use SolidWP\Performance\Timer\Tables\Timer_Table; |
| 20 |
|
| 21 |
/** |
| 22 |
* Registers database related functionality in the container. |
| 23 |
* |
| 24 |
* @package SolidWP\Performance |
| 25 |
*/ |
| 26 |
final class Provider extends Service_Provider { |
| 27 |
|
| 28 |
public const SCHEMA_TABLES = 'solid_performance.database.schema_tables'; |
| 29 |
|
| 30 |
/** |
| 31 |
* @inheritDoc |
| 32 |
*/ |
| 33 |
public function register(): void { |
| 34 |
$this->register_schema(); |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Configure the stellarwp/schema library. |
| 39 |
* |
| 40 |
* @throws DatabaseQueryException If we failed to create or update the database tables. |
| 41 |
* |
| 42 |
* @return void |
| 43 |
*/ |
| 44 |
private function register_schema(): void { |
| 45 |
Config::set_container( $this->container ); |
| 46 |
Config::set_db( DB::class ); |
| 47 |
|
| 48 |
// Add all schema tables to be registered here. |
| 49 |
$this->container->setVar( |
| 50 |
self::SCHEMA_TABLES, |
| 51 |
[ |
| 52 |
Cache_Lock::class, |
| 53 |
Timer_Table::class, |
| 54 |
] |
| 55 |
); |
| 56 |
|
| 57 |
try { |
| 58 |
Register::tables( $this->container->getVar( self::SCHEMA_TABLES ) ); |
| 59 |
} catch ( DatabaseQueryException $e ) { |
| 60 |
$this->container->get( LoggerInterface::class )->emergency( |
| 61 |
'Unable to create or update database tables', |
| 62 |
[ |
| 63 |
'query_errors' => $e->getQueryErrors(), |
| 64 |
'query' => $e->getQuery(), |
| 65 |
'exception' => $e, |
| 66 |
] |
| 67 |
); |
| 68 |
|
| 69 |
throw $e; |
| 70 |
} |
| 71 |
} |
| 72 |
} |
| 73 |
|