[DoctrineBridge] Fix arguments when registering event listeners on multiple connections
Fixes #4712
This commit is contained in:
parent
0bf3c068d7
commit
e97cd61a89
@ -15,6 +15,12 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
|
||||
/**
|
||||
* Registers event listeners and subscribers to the available doctrine connections.
|
||||
*
|
||||
* @author Jeremy Mikola <jmikola@gmail.com>
|
||||
* @author Alexander <iam.asm89@gmail.com>
|
||||
*/
|
||||
class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
|
||||
{
|
||||
private $connections;
|
||||
@ -38,6 +44,9 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
|
||||
$this->tagPrefix = $tagPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
if (!$container->hasParameter($this->connections)) {
|
||||
@ -80,18 +89,12 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
|
||||
private function groupByConnection(array $services, $isListener = false)
|
||||
{
|
||||
$grouped = array();
|
||||
foreach (array_keys($this->connections) as $con) {
|
||||
foreach ($allCons = array_keys($this->connections) as $con) {
|
||||
$grouped[$con] = array();
|
||||
}
|
||||
|
||||
foreach ($services as $id => $instances) {
|
||||
foreach ($instances as $instance) {
|
||||
$cons = isset($instance['connection']) ? array($instance['connection']) : array_keys($this->connections);
|
||||
foreach ($cons as $con) {
|
||||
if (!isset($grouped[$con])) {
|
||||
throw new \RuntimeException(sprintf('The Doctrine connection "%s" referenced in service "%s" does not exist. Available connections names: %s', $con, $id, implode(', ', array_keys($this->connections))));
|
||||
}
|
||||
|
||||
if ($isListener) {
|
||||
if (!isset($instance['event'])) {
|
||||
throw new \InvalidArgumentException(sprintf('Doctrine event listener "%s" must specify the "event" attribute.', $id));
|
||||
@ -101,17 +104,22 @@ class RegisterEventListenersAndSubscribersPass implements CompilerPassInterface
|
||||
if (isset($instance['lazy']) && $instance['lazy']) {
|
||||
$this->container->getDefinition($id)->setPublic(true);
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($grouped[$con][$id])) {
|
||||
$cons = isset($instance['connection']) ? array($instance['connection']) : $allCons;
|
||||
foreach ($cons as $con) {
|
||||
if (!isset($grouped[$con])) {
|
||||
throw new \RuntimeException(sprintf('The Doctrine connection "%s" referenced in service "%s" does not exist. Available connections names: %s', $con, $id, implode(', ', array_keys($this->connections))));
|
||||
}
|
||||
|
||||
if ($isListener && isset($grouped[$con][$id])) {
|
||||
$grouped[$con][$id]['event'] = array_merge($grouped[$con][$id]['event'], $instance['event']);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
$grouped[$con][$id] = $instance;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $grouped;
|
||||
}
|
||||
|
Reference in New Issue
Block a user