Commit 904189ed authored by catch's avatar catch

Issue #3130973 by daffie, plach, Charlie ChX Negyesi: Make the backend...

Issue #3130973 by daffie, plach, Charlie ChX Negyesi: Make the backend overridable service discovery also check the database type for an overridden service

(cherry picked from commit 0e6ed376)
parent 8dd0e326
......@@ -37,6 +37,7 @@ class BackendCompilerPass implements CompilerPassInterface {
* {@inheritdoc}
*/
public function process(ContainerBuilder $container) {
$driver_backend = NULL;
if ($container->hasParameter('default_backend')) {
$default_backend = $container->getParameter('default_backend');
// Opt out from the default backend.
......@@ -46,7 +47,8 @@ public function process(ContainerBuilder $container) {
}
else {
try {
$default_backend = $container->get('database')->driver();
$driver_backend = $container->get('database')->driver();
$default_backend = $container->get('database')->databaseType();
$container->set('database', NULL);
}
catch (\Exception $e) {
......@@ -62,7 +64,10 @@ public function process(ContainerBuilder $container) {
if ($container->hasAlias($id)) {
continue;
}
if ($container->hasDefinition("$default_backend.$id") || $container->hasAlias("$default_backend.$id")) {
if ($container->hasDefinition("$driver_backend.$id") || $container->hasAlias("$driver_backend.$id")) {
$container->setAlias($id, new Alias("$driver_backend.$id"));
}
elseif ($container->hasDefinition("$default_backend.$id") || $container->hasAlias("$default_backend.$id")) {
$container->setAlias($id, new Alias("$default_backend.$id"));
}
}
......
......@@ -87,6 +87,25 @@ public function providerTestProcess() {
$container->setParameter('default_backend', '');
$data[] = [$prefix . 'Default', $container];
// Set the mysql and the DrivertestMysql service, now the DrivertestMysql
// service, as it is the driver override, should be used.
$container = $this->getDrivertestMysqlContainer($service);
$container->setDefinition('mysql.service', new Definition(__NAMESPACE__ . '\\ServiceClassMysql'));
$container->setDefinition('DrivertestMysql.service', new Definition(__NAMESPACE__ . '\\ServiceClassDrivertestMysql'));
$data[] = [$prefix . 'DrivertestMysql', $container];
// Set the mysql service, now the mysql service, as it is the database_type
// override, should be used.
$container = $this->getDrivertestMysqlContainer($service);
$container->setDefinition('mysql.service', new Definition(__NAMESPACE__ . '\\ServiceClassMysql'));
$data[] = [$prefix . 'Mysql', $container];
// Set the DrivertestMysql service, now the DrivertestMysql service, as it
// is the driver override, should be used.
$container = $this->getDrivertestMysqlContainer($service);
$container->setDefinition('DrivertestMysql.service', new Definition(__NAMESPACE__ . '\\ServiceClassDrivertestMysql'));
$data[] = [$prefix . 'DrivertestMysql', $container];
return $data;
}
......@@ -126,6 +145,24 @@ protected function getMysqlContainer($service) {
return $container;
}
/**
* Creates a container with a DrivertestMysql database mock definition in it.
*
* This is necessary because the container clone does not clone the parameter
* bag so the setParameter() call effects the parent container as well.
*
* @param $service
*
* @return \Symfony\Component\DependencyInjection\ContainerBuilder
*/
protected function getDrivertestMysqlContainer($service) {
$container = new ContainerBuilder();
$container->setDefinition('service', $service);
$mock = $this->getMockBuilder('Drupal\driver_test\Driver\Database\DrivertestMysql\Connection')->setMethods(NULL)->disableOriginalConstructor()->getMock();
$container->set('database', $mock);
return $container;
}
}
class ServiceClassDefault {
......@@ -139,3 +176,6 @@ class ServiceClassMariaDb extends ServiceClassMysql {
class ServiceClassSqlite extends ServiceClassDefault {
}
class ServiceClassDrivertestMysql extends ServiceClassDefault {
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment