mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-16 19:54:58 +00:00
cs: Fix code style (safe rules only).
This commit is contained in:
@@ -1,38 +1,48 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\ThirdPartyBundle\DependencyInjection\CompilerPass;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeManager;
|
||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
use LogicException;
|
||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
use function in_array;
|
||||
|
||||
/**
|
||||
* Load services tagged chill_3party.provider and add them to the service
|
||||
* definition of manager
|
||||
*
|
||||
* Load services tagged chill_3party.provider and add them to the service
|
||||
* definition of manager.
|
||||
*/
|
||||
class ThirdPartyTypeCompilerPass implements CompilerPassInterface
|
||||
{
|
||||
const TAG = 'chill_3party.provider';
|
||||
|
||||
public const TAG = 'chill_3party.provider';
|
||||
|
||||
public function process(ContainerBuilder $container)
|
||||
{
|
||||
$definition = $container->getDefinition(ThirdPartyTypeManager::class);
|
||||
$usedKeys = [];
|
||||
|
||||
|
||||
foreach ($container->findTaggedServiceIds(self::TAG) as $id => $tags) {
|
||||
$taggedService = $container->getDefinition($id);
|
||||
// check forr keys already in use :
|
||||
$key = $taggedService->getClass()::getKey();
|
||||
if (\in_array($key, $usedKeys)) {
|
||||
throw new \LogicException(sprintf("Tag with key \"%s\" is already in used",
|
||||
$key));
|
||||
|
||||
if (in_array($key, $usedKeys)) {
|
||||
throw new LogicException(sprintf(
|
||||
'Tag with key "%s" is already in used',
|
||||
$key
|
||||
));
|
||||
}
|
||||
$usedKeys[] = $key;
|
||||
// alter the service definition of manager
|
||||
$definition->addMethodCall('addProvider', [ new Reference($id) ]);
|
||||
$definition->addMethodCall('addProvider', [new Reference($id)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user