Skip to content

Commit ff2ac2c

Browse files
committed
Use DI exceptions in components compiler passes
1 parent 817cecb commit ff2ac2c

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

DependencyInjection/CompilerPass/RegisterEventListenersAndSubscribersPass.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
1515
use Symfony\Component\DependencyInjection\Reference;
1616
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
17+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
18+
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
1719

1820
/**
1921
* Registers event listeners and subscribers to the available doctrine connections.
@@ -77,7 +79,7 @@ public function process(ContainerBuilder $container)
7779
uasort($subscribers, $sortFunc);
7880
foreach ($subscribers as $id => $instance) {
7981
if ($container->getDefinition($id)->isAbstract()) {
80-
throw new \InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event subscriber.', $id));
82+
throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event subscriber.', $id));
8183
}
8284

8385
$em->addMethodCall('addEventSubscriber', array(new Reference($id)));
@@ -93,7 +95,7 @@ public function process(ContainerBuilder $container)
9395
uasort($listeners, $sortFunc);
9496
foreach ($listeners as $id => $instance) {
9597
if ($container->getDefinition($id)->isAbstract()) {
96-
throw new \InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event listener.', $id));
98+
throw new InvalidArgumentException(sprintf('The abstract service "%s" cannot be tagged as a doctrine event listener.', $id));
9799
}
98100

99101
$em->addMethodCall('addEventListener', array(
@@ -116,7 +118,7 @@ private function groupByConnection(array $services, $isListener = false)
116118
foreach ($instances as $instance) {
117119
if ($isListener) {
118120
if (!isset($instance['event'])) {
119-
throw new \InvalidArgumentException(sprintf('Doctrine event listener "%s" must specify the "event" attribute.', $id));
121+
throw new InvalidArgumentException(sprintf('Doctrine event listener "%s" must specify the "event" attribute.', $id));
120122
}
121123
$instance['event'] = array($instance['event']);
122124

@@ -128,7 +130,7 @@ private function groupByConnection(array $services, $isListener = false)
128130
$cons = isset($instance['connection']) ? array($instance['connection']) : $allCons;
129131
foreach ($cons as $con) {
130132
if (!isset($grouped[$con])) {
131-
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))));
133+
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))));
132134
}
133135

134136
if ($isListener && isset($grouped[$con][$id])) {

DependencyInjection/CompilerPass/RegisterMappingsPass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Symfony\Component\DependencyInjection\Definition;
1616
use Symfony\Component\DependencyInjection\Reference;
1717
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
18+
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
1819

1920
/**
2021
* Base class for the doctrine bundles to provide a compiler pass class that
@@ -231,7 +232,7 @@ private function getManagerName(ContainerBuilder $container)
231232
}
232233
}
233234

234-
throw new \InvalidArgumentException(sprintf(
235+
throw new InvalidArgumentException(sprintf(
235236
'Could not find the manager name parameter in the container. Tried the following parameter names: "%s"',
236237
implode('", "', $this->managerParameters)
237238
));

0 commit comments

Comments
 (0)