chore: complete update
This commit is contained in:
55
src/Framework/Database/EntityManagerInitializer.php
Normal file
55
src/Framework/Database/EntityManagerInitializer.php
Normal file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Framework\Database;
|
||||
|
||||
use App\Domain\User\User;
|
||||
use App\Framework\Attributes\Singleton;
|
||||
use App\Framework\Database\Config\DatabaseConfig;
|
||||
use App\Framework\Database\Config\PoolConfig;
|
||||
use App\Framework\Database\Driver\DriverConfig;
|
||||
use App\Framework\Database\Driver\DriverType;
|
||||
use App\Framework\DI\Container;
|
||||
use App\Framework\DI\Initializer;
|
||||
|
||||
final readonly class EntityManagerInitializer
|
||||
{
|
||||
#[Initializer]
|
||||
public function __invoke(Container $container): EntityManager
|
||||
{
|
||||
$config = [
|
||||
'driver' => 'mysql',
|
||||
'host' => 'db',
|
||||
'port' => 3306,
|
||||
'username' => 'mdb-user',
|
||||
'password' => 'dfghreh5465fghfgh',
|
||||
'database' => 'database',
|
||||
];
|
||||
|
||||
$newConfig = new DatabaseConfig(
|
||||
new DriverConfig(
|
||||
driverType: DriverType::MYSQL,
|
||||
host : 'mysql',
|
||||
port : 3306,
|
||||
database : 'database',
|
||||
username : "mdb-user",
|
||||
password : 'dfghreh5465fghfgh',
|
||||
charset : 'utf8mb4',
|
||||
),
|
||||
new PoolConfig(
|
||||
enabled: true,
|
||||
maxConnections: 5,
|
||||
minConnections: 2,
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
#$connection = DatabaseFactory::createConnection($config);
|
||||
|
||||
$db = new DatabaseManager($config);
|
||||
|
||||
$container->singleton(DatabaseManager::class, $db);
|
||||
$container->singleton(ConnectionInterface::class, $db->getConnection());
|
||||
|
||||
return EntityManagerFactory::create($db);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user