class Doctrine
{
// Just rename __construct to create and make it static
static function create()
{
$doctrineLoader = new ClassLoader('Doctrine');
$doctrineLoader->register();
$doctrineConfig = new Configuration();
$doctrineParams = [
'driver' => 'pdo_mysql',
'dbname' => 'levelup',
'host' => '127.0.0.1',
'user' => 'root',
'password' => 'toor',
];
return DriverManager::getConnection($doctrineParams, $doctrineConfig);
}
}
Then in services.yml file:
doctrine:
class: Doctrine\DBAL\Connection
factory_class: 'Localhost\Service\Doctrine'
factory_method: 'create'