Source of file HasService.php
Size: 1,298 Bytes - Last Modified: 2021-12-24T06:51:36+00:00
/var/www/docs.ssmods.com/process/src/src/DependencyInjection/CompilerPass/HasService.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 | <?php namespace Heystack\Core\DependencyInjection\CompilerPass; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Reference; /** * Class HasService * @package Heystack\Core\DependencyInjection\CompilerPass */ abstract class HasService implements CompilerPassInterface { /** * The name of the service in the container * @return string */ abstract protected function getServiceName(); /** * The method name used to set the service * @return string */ abstract protected function getServiceSetterName(); /** * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container * @return void */ public function process(ContainerBuilder $container) { $serviceName = $this->getServiceName(); if (!$serviceName || !$container->hasDefinition($serviceName)) { return; } foreach ($container->findTaggedServiceIds(sprintf('set.%s', $serviceName)) as $id => $_) { $container->getDefinition($id)->addMethodCall( $this->getServiceSetterName(), [new Reference($serviceName)] ); } } } |