1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 22:44:05 +00:00
tenancy/src/Database/TenantDatabaseManagers/SQLiteDatabaseManager.php
Abrar Ahmad 8e3b74f9d1
[4.x] Finish incomplete and missing tests (#947)
* complete test sqlite manager customize path

* complete test seed command works

* complete uniqe exists test

* Update SingleDatabaseTenancyTest.php

* refactor the ternary into if condition

* custom path

* simplify if condition

* random dir name

* Update SingleDatabaseTenancyTest.php

* Update CommandsTest.php

* prefix random DB name with custom_

Co-authored-by: Samuel Štancl <samuel@archte.ch>
2022-09-24 04:08:44 +02:00

61 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\TenantDatabaseManagers;
use Stancl\Tenancy\Database\Contracts\TenantDatabaseManager;
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
use Throwable;
class SQLiteDatabaseManager implements TenantDatabaseManager
{
/**
* SQLite Database path without ending slash.
*/
public static string|null $path = null;
public function createDatabase(TenantWithDatabase $tenant): bool
{
try {
return (bool) file_put_contents($this->getPath($tenant->database()->getName()), '');
} catch (Throwable) {
return false;
}
}
public function deleteDatabase(TenantWithDatabase $tenant): bool
{
try {
return unlink($this->getPath($tenant->database()->getName()));
} catch (Throwable) {
return false;
}
}
public function databaseExists(string $name): bool
{
return file_exists($this->getPath($name));
}
public function makeConnectionConfig(array $baseConfig, string $databaseName): array
{
$baseConfig['database'] = database_path($databaseName);
return $baseConfig;
}
public function setConnection(string $connection): void
{
//
}
public function getPath(string $name): string
{
if (static::$path) {
return static::$path . DIRECTORY_SEPARATOR . $name;
}
return database_path($name);
}
}