I hope all are doing good. I am having a trouble setting lazy object in di.
This is the code .
$di->set('default_connection', $di->lazyNew('Aura\Sql\ExtendedPdo'));
$di->set('query_factory', $di->lazyNew('Aura\SqlMapper_Bundle\Query\ConnectedQueryFactory'));
$di->set('connection_locator', $di->lazyNew('Aura\Sql\ConnectionLocator'));
$di->params['Aura\Sql\ExtendedPdo']['dsn'] = getenv('CONNECTION_DSN');
$di->params['Aura\Sql\ExtendedPdo']['username'] = getenv('CONNECTION_USERNAME');
$di->params['Aura\Sql\ExtendedPdo']['password'] = getenv('CONNECTION_PASSWORD');
$di->params['Aura\SqlQuery\QueryFactory']['db'] = getenv('CONNECTION_TYPE');
$di->params['Aura\Sql\ConnectionLocator']['default'] = function () use ($di) {
return $di->get('default_connection');
};
$di->params['Aura\SqlMapper_Bundle\Query\ConnectedQueryFactory']['query'] = $di->lazyNew('Aura\SqlQuery\QueryFactory');
I need $di->params['Aura\Sql\ConnectionLocator']['default'] to be a closure. But I am wondering what is the best way to acheive it.
I have tried lazy but it didn't worked as expected.
Thank you.