irishdan /
NotificationBundle
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | |||
| 4 | namespace IrishDan\NotificationBundle\DependencyInjection; |
||
| 5 | |||
| 6 | use IrishDan\NotificationBundle\Adapter\MessageAdapterInterface; |
||
| 7 | use Symfony\Bundle\MakerBundle\MakerInterface; |
||
| 8 | use Symfony\Component\DependencyInjection\ContainerBuilder; |
||
| 9 | use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; |
||
| 10 | use Symfony\Component\DependencyInjection\Reference; |
||
| 11 | // use App\Mail\TransportChain; |
||
| 12 | |||
| 13 | class AdapterPass implements CompilerPassInterface |
||
| 14 | { |
||
| 15 | public function process(ContainerBuilder $container) |
||
| 16 | { |
||
| 17 | if (!$container->has('notification.channel_subscriber')) { |
||
| 18 | return; |
||
| 19 | } |
||
| 20 | |||
| 21 | // Add all adapters to the subscriber so ot can handle |
||
| 22 | // any type of message. |
||
| 23 | $subscriberDefinition = $container->findDefinition('notification.channel_subscriber'); |
||
| 24 | |||
| 25 | // find all service IDs with the app.mail_transport tag. |
||
| 26 | // @TODO: Inject only the adapters that are used |
||
| 27 | $taggedServices = $container->findTaggedServiceIds('notification.adapter'); |
||
| 28 | |||
| 29 | foreach ($taggedServices as $id => $tags) { |
||
| 30 | $def = $container->getDefinition($id); |
||
| 31 | $class = $container->getParameterBag()->resolveValue($def->getClass()); |
||
| 32 | |||
| 33 | if (!is_subclass_of($class, MessageAdapterInterface::class)) { |
||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 34 | throw new \InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, MakerInterface::class)); |
||
| 35 | } |
||
| 36 | |||
| 37 | $subscriberDefinition->addMethodCall('addAdapter', [$id, new Reference($id)]); |
||
| 38 | } |
||
| 39 | } |
||
| 40 | } |