vendor/sonata-project/admin-bundle/src/DependencyInjection/Compiler/ModelManagerCompilerPass.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Sonata Project package.
  5.  *
  6.  * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Sonata\AdminBundle\DependencyInjection\Compiler;
  12. use Sonata\AdminBundle\Model\ModelManagerInterface;
  13. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  14. use Symfony\Component\DependencyInjection\ContainerBuilder;
  15. use Symfony\Component\DependencyInjection\Exception\LogicException;
  16. /**
  17.  * This class injects available model managers to services which depend on them.
  18.  *
  19.  * @final since sonata-project/admin-bundle 3.52
  20.  *
  21.  * @author Gaurav Singh Faudjdar <faujdar@gmail.com>
  22.  */
  23. final class ModelManagerCompilerPass implements CompilerPassInterface
  24. {
  25.     public const MANAGER_TAG 'sonata.admin.manager';
  26.     public function process(ContainerBuilder $container): void
  27.     {
  28.         $availableManagers = [];
  29.         // NEXT_MAJOR: Replace the `foreach()` clause with the following one.
  30.         // foreach ($container->findTaggedServiceIds(self::MANAGER_TAG) as $id => $tags) {
  31.         foreach ($container->getDefinitions() as $id => $definition) {
  32.             // NEXT_MAJOR: Remove this check.
  33.             if (!$definition->hasTag(self::MANAGER_TAG) && !== strpos($id'sonata.admin.manager.')) {
  34.                 continue;
  35.             }
  36.             if (!is_subclass_of($definition->getClass(), ModelManagerInterface::class)) {
  37.                 throw new LogicException(sprintf('Service "%s" must implement `%s`.'$idModelManagerInterface::class));
  38.             }
  39.             // NEXT_MAJOR: Remove this check.
  40.             if (!$definition->hasTag(self::MANAGER_TAG)) {
  41.                 @trigger_error(sprintf(
  42.                     'Not setting the "%s" tag on the "%s" service is deprecated since sonata-project/admin-bundle 3.60.',
  43.                     self::MANAGER_TAG,
  44.                     $id
  45.                 ), E_USER_DEPRECATED);
  46.                 $definition->addTag(self::MANAGER_TAG);
  47.             }
  48.             $availableManagers[$id] = $definition;
  49.         }
  50.         if (!empty($availableManagers)) {
  51.             $bundles $container->getParameter('kernel.bundles');
  52.             if (isset($bundles['MakerBundle'])) {
  53.                 $adminMakerDefinition $container->getDefinition('sonata.admin.maker');
  54.                 $adminMakerDefinition->replaceArgument(1$availableManagers);
  55.             }
  56.         }
  57.     }
  58. }