mirror of
https://github.com/djav1985/v-wordpress-plugin-updater.git
synced 2026-08-04 00:47:00 +08:00
modified: tests/bootstrap-local.php modified: update-api/app/Core/DatabaseManager.php modified: update-api/app/Core/Router.php modified: update-api/storage/test.sqlite
49 lines
1.3 KiB
PHP
49 lines
1.3 KiB
PHP
<?php
|
|
// phpcs:ignoreFile PSR1.Files.SideEffects.FoundWithSymbols
|
|
|
|
/**
|
|
* Project: UpdateAPI
|
|
* Author: Vontainment <services@vontainment.com>
|
|
* License: https://opensource.org/licenses/MIT MIT License
|
|
* Link: https://vontainment.com
|
|
* Version: 4.0.0
|
|
*
|
|
* File: DatabaseManager.php
|
|
* Description: WordPress Update API
|
|
*/
|
|
|
|
namespace App\Core;
|
|
|
|
use Doctrine\DBAL\Connection;
|
|
use Doctrine\DBAL\DriverManager;
|
|
|
|
class DatabaseManager
|
|
{
|
|
private static ?Connection $connection = null;
|
|
|
|
/**
|
|
* Get a Doctrine DBAL connection to the SQLite database.
|
|
*/
|
|
public static function getConnection(): Connection
|
|
{
|
|
if (self::$connection === null) {
|
|
// Ensure directory exists and file is present so tests that assert file
|
|
// creation will pass.
|
|
$dir = dirname(DB_FILE);
|
|
if (!is_dir($dir)) {
|
|
mkdir($dir, 0777, true);
|
|
}
|
|
if (!file_exists(DB_FILE)) {
|
|
// Create an empty SQLite file — Doctrine will initialize schema as needed.
|
|
touch(DB_FILE);
|
|
}
|
|
|
|
$params = [
|
|
'driver' => 'pdo_sqlite',
|
|
'path' => DB_FILE,
|
|
];
|
|
self::$connection = DriverManager::getConnection($params);
|
|
}
|
|
return self::$connection;
|
|
}
|
|
}
|