vendor/sonata-project/admin-bundle/src/Admin/Pool.php line 777

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\Admin;
  12. use Sonata\AdminBundle\Exception\AdminClassNotFoundException;
  13. use Sonata\AdminBundle\Exception\AdminCodeNotFoundException;
  14. use Sonata\AdminBundle\Exception\TooManyAdminClassException;
  15. use Sonata\AdminBundle\SonataConfiguration;
  16. use Sonata\AdminBundle\Templating\MutableTemplateRegistryInterface;
  17. use Symfony\Component\DependencyInjection\ContainerInterface;
  18. use Symfony\Component\PropertyAccess\PropertyAccess;
  19. use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
  20. /**
  21.  * @psalm-type Group = array{
  22.  *  label: string,
  23.  *  label_catalogue: string,
  24.  *  icon: string,
  25.  *  item_adds: array,
  26.  *  items: array<array-key, array{
  27.  *      admin?: string,
  28.  *      label?: string,
  29.  *      roles: list<string>,
  30.  *      route?: string,
  31.  *      router_absolute: bool,
  32.  *      route_params: array<string, string>
  33.  *  }>,
  34.  *  keep_open: bool,
  35.  *  on_top: bool,
  36.  *  roles: list<string>
  37.  * }
  38.  *
  39.  * @final since sonata-project/admin-bundle 3.52
  40.  *
  41.  * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  42.  */
  43. class Pool
  44. {
  45.     public const DEFAULT_ADMIN_KEY 'default';
  46.     /**
  47.      * @var ContainerInterface
  48.      */
  49.     protected $container;
  50.     /**
  51.      * @var string[]
  52.      */
  53.     protected $adminServiceIds = [];
  54.     /**
  55.      * @var array
  56.      * @phpstan-var array<string, array<string, mixed>>
  57.      * @psalm-var array<string, Group>
  58.      */
  59.     protected $adminGroups = [];
  60.     /**
  61.      * @var array<string, string[]>
  62.      *
  63.      * @phpstan-var array<class-string, string[]>
  64.      */
  65.     protected $adminClasses = [];
  66.     /**
  67.      * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry "sonata.admin.global_template_registry" instead
  68.      *
  69.      * @var array
  70.      */
  71.     protected $templates = [];
  72.     /**
  73.      * @var array
  74.      */
  75.     protected $assets = [];
  76.     /**
  77.      * NEXT_MAJOR: Remove this property.
  78.      *
  79.      * @deprecated since sonata-project/admin-bundle 3.83, will be dropped in 4.0.
  80.      *
  81.      * @var string
  82.      */
  83.     protected $title;
  84.     /**
  85.      * NEXT_MAJOR: Remove this property.
  86.      *
  87.      * @deprecated since sonata-project/admin-bundle 3.83, will be dropped in 4.0.
  88.      *
  89.      * @var string
  90.      */
  91.     protected $titleLogo;
  92.     /**
  93.      * NEXT_MAJOR: Remove this property.
  94.      *
  95.      * @deprecated since sonata-project/admin-bundle 3.83, will be dropped in 4.0.
  96.      *
  97.      * @var array
  98.      */
  99.     protected $options = [];
  100.     /**
  101.      * NEXT_MAJOR: Remove this property.
  102.      *
  103.      * @var PropertyAccessorInterface
  104.      *
  105.      * @deprecated since sonata-project/admin-bundle 3.82, will be dropped in 4.0.
  106.      */
  107.     protected $propertyAccessor;
  108.     /**
  109.      * NEXT_MAJOR: Remove this property.
  110.      *
  111.      * @deprecated since sonata-project/admin-bundle 3.89 and will be removed in 4.0.
  112.      *
  113.      * @var MutableTemplateRegistryInterface
  114.      */
  115.     private $templateRegistry;
  116.     /**
  117.      * NEXT_MAJOR: Remove $propertyAccessor argument.
  118.      * NEXT_MAJOR: Rename $titleOrAdminServiceIds to $adminServices, $logoTitleOrAdminGroups to $adminGroups and
  119.      * $optionsOrAdminClasses to $adminClasses and add "array" type declaration.
  120.      *
  121.      * @param string|array $titleOrAdminServiceIds
  122.      * @param string|array $logoTitleOrAdminGroups
  123.      * @param array        $optionsOrAdminClasses
  124.      */
  125.     public function __construct(
  126.         ContainerInterface $container,
  127.         $titleOrAdminServiceIds = [],
  128.         $logoTitleOrAdminGroups = [],
  129.         $optionsOrAdminClasses = [],
  130.         ?PropertyAccessorInterface $propertyAccessor null
  131.     ) {
  132.         $this->container $container;
  133.         // NEXT_MAJOR: Uncomment the following lines
  134.         // $this->adminServiceIds = $titleOrAdminServiceIds;
  135.         // $this->adminGroups = $logoTitleOrAdminGroups;
  136.         // $this->adminClasses = $optionsOrAdminClasses;
  137.         // NEXT_MAJOR: Remove this block.
  138.         if (\is_array($titleOrAdminServiceIds)) {
  139.             $this->adminServiceIds $titleOrAdminServiceIds;
  140.         } else {
  141.             @trigger_error(sprintf(
  142.                 'Passing other type than array as argument 2 to "%s()" is deprecated since'
  143.                 .' sonata-project/admin-bundle 3.86 and will throw "%s" exception in 4.0.',
  144.                 __METHOD__,
  145.                 \TypeError::class
  146.             ), \E_USER_DEPRECATED);
  147.             $this->title $titleOrAdminServiceIds;
  148.         }
  149.         // NEXT_MAJOR: Remove this block.
  150.         if (\is_array($logoTitleOrAdminGroups)) {
  151.             $this->adminGroups $logoTitleOrAdminGroups;
  152.         } else {
  153.             @trigger_error(sprintf(
  154.                 'Passing other type than array as argument 3 to "%s()" is deprecated since'
  155.                 .' sonata-project/admin-bundle 3.86 and will throw "%s" exception in 4.0.',
  156.                 __METHOD__,
  157.                 \TypeError::class
  158.             ), \E_USER_DEPRECATED);
  159.             $this->titleLogo $logoTitleOrAdminGroups;
  160.         }
  161.         // NEXT_MAJOR: Remove this block.
  162.         if (\is_array($titleOrAdminServiceIds) && \is_array($logoTitleOrAdminGroups)) {
  163.             $this->adminClasses $optionsOrAdminClasses;
  164.         } else {
  165.             $this->options $optionsOrAdminClasses;
  166.         }
  167.         // NEXT_MAJOR: Remove this block.
  168.         if (null !== $propertyAccessor) {
  169.             @trigger_error(sprintf(
  170.                 'Passing an "%s" instance as argument 4 to "%s()" is deprecated since sonata-project/admin-bundle 3.82.',
  171.                 PropertyAccessorInterface::class,
  172.                 __METHOD__
  173.             ), \E_USER_DEPRECATED);
  174.         }
  175.         // NEXT_MAJOR: Remove next line.
  176.         $this->propertyAccessor $propertyAccessor;
  177.     }
  178.     /**
  179.      * NEXT_MAJOR: Remove this method.
  180.      *
  181.      * @internal
  182.      */
  183.     public function setDeprecatedPropertiesForBC(string $titlestring $titleLogo, array $options): void
  184.     {
  185.         $this->title $title;
  186.         $this->titleLogo $titleLogo;
  187.         $this->options $options;
  188.     }
  189.     /**
  190.      * NEXT_MAJOR: Remove this method.
  191.      *
  192.      * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0.
  193.      *
  194.      * @return array
  195.      */
  196.     public function getGroups()
  197.     {
  198.         @trigger_error(sprintf(
  199.             'Method "%s()" is deprecated since sonata-project/admin-bundle 3.83 and will be removed in version 4.0.',
  200.             __METHOD__
  201.         ), \E_USER_DEPRECATED);
  202.         $groups $this->adminGroups;
  203.         foreach ($this->adminGroups as $name => $adminGroup) {
  204.             foreach ($adminGroup as $id => $options) {
  205.                 $groups[$name][$id] = $this->getInstance($id);
  206.             }
  207.         }
  208.         return $groups;
  209.     }
  210.     /**
  211.      * NEXT_MAJOR: Remove this method.
  212.      *
  213.      * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0.
  214.      *
  215.      * Returns whether an admin group exists or not.
  216.      *
  217.      * @param string $group
  218.      *
  219.      * @return bool
  220.      */
  221.     public function hasGroup($group)
  222.     {
  223.         @trigger_error(sprintf(
  224.             'Method "%s()" is deprecated since sonata-project/admin-bundle 3.83 and will be removed in version 4.0.',
  225.             __METHOD__
  226.         ), \E_USER_DEPRECATED);
  227.         return isset($this->adminGroups[$group]);
  228.     }
  229.     /**
  230.      * @return array
  231.      * @phpstan-return array<string, array{
  232.      *  label: string,
  233.      *  label_catalogue: string,
  234.      *  icon: string,
  235.      *  item_adds: array,
  236.      *  items: array<array-key, AdminInterface>,
  237.      *  keep_open: bool,
  238.      *  on_top: bool,
  239.      *  roles: list<string>
  240.      * }>
  241.      */
  242.     public function getDashboardGroups()
  243.     {
  244.         $groups = [];
  245.         foreach ($this->adminGroups as $name => $adminGroup) {
  246.             if (isset($adminGroup['items'])) {
  247.                 $items array_filter(array_map(function (array $item): ?AdminInterface {
  248.                     if (!isset($item['admin']) || empty($item['admin'])) {
  249.                         return null;
  250.                     }
  251.                     $admin $this->getInstance($item['admin']);
  252.                     if (!$admin->showIn(AbstractAdmin::CONTEXT_DASHBOARD)) {
  253.                         return null;
  254.                     }
  255.                     return $admin;
  256.                 }, $adminGroup['items']));
  257.                 if ([] !== $items) {
  258.                     $groups[$name] = ['items' => $items] + $adminGroup;
  259.                 }
  260.             }
  261.         }
  262.         return $groups;
  263.     }
  264.     /**
  265.      * NEXT_MAJOR: Remove this method.
  266.      *
  267.      * @deprecated since sonata-project/admin-bundle 3.83 and will be removed in 4.0.
  268.      *
  269.      * Returns all admins related to the given $group.
  270.      *
  271.      * @param string $group
  272.      *
  273.      * @throws \InvalidArgumentException
  274.      *
  275.      * @return AdminInterface[]
  276.      */
  277.     public function getAdminsByGroup($group)
  278.     {
  279.         @trigger_error(sprintf(
  280.             'Method "%s()" is deprecated since sonata-project/admin-bundle 3.83 and will be removed in version 4.0.',
  281.             __METHOD__
  282.         ), \E_USER_DEPRECATED);
  283.         if (!isset($this->adminGroups[$group])) {
  284.             throw new \InvalidArgumentException(sprintf('Group "%s" not found in admin pool.'$group));
  285.         }
  286.         $admins = [];
  287.         if (!isset($this->adminGroups[$group]['items'])) {
  288.             return $admins;
  289.         }
  290.         foreach ($this->adminGroups[$group]['items'] as $item) {
  291.             if (isset($item['admin']) && !empty($item['admin'])) {
  292.                 $admins[] = $this->getInstance($item['admin']);
  293.             }
  294.         }
  295.         return $admins;
  296.     }
  297.     /**
  298.      * Return the admin related to the given $class.
  299.      *
  300.      * @param string $class
  301.      *
  302.      * @throws AdminClassNotFoundException if there is no admin class for the class provided
  303.      * @throws TooManyAdminClassException  if there is multiple admin class for the class provided
  304.      *
  305.      * @return AdminInterface|null
  306.      *
  307.      * @phpstan-param class-string $class
  308.      * @phpstan-return AdminInterface|null
  309.      */
  310.     public function getAdminByClass($class)
  311.     {
  312.         if (!$this->hasAdminByClass($class)) {
  313.             @trigger_error(sprintf(
  314.                 'Calling %s() when there is no admin for the class %s is deprecated since sonata-project/admin-bundle'
  315.                 .' 3.69 and will throw an exception in 4.0. Use %s::hasAdminByClass() to know if the admin exists.',
  316.                 __METHOD__,
  317.                 $class,
  318.                 __CLASS__
  319.             ), \E_USER_DEPRECATED);
  320.             // NEXT_MAJOR : remove the previous `trigger_error()` call, the `return null` statement,
  321.             // uncomment the following exception and declare AdminInterface as return type
  322.             //
  323.             // throw new AdminClassNotFoundException(sprintf('Pool has no admin for the class %s.', $class));
  324.             return null;
  325.         }
  326.         if (isset($this->adminClasses[$class][self::DEFAULT_ADMIN_KEY])) {
  327.             return $this->getInstance($this->adminClasses[$class][self::DEFAULT_ADMIN_KEY]);
  328.         }
  329.         if (!== \count($this->adminClasses[$class])) {
  330.             // NEXT_MAJOR: Throw TooManyAdminClassException instead.
  331.             throw new \RuntimeException(sprintf(
  332.                 'Unable to find a valid admin for the class: %s, there are too many registered: %s.'
  333.                 .' Please define a default one with the tag attribute `default: true` in your admin configuration.',
  334.                 $class,
  335.                 implode(', '$this->adminClasses[$class])
  336.             ));
  337.         }
  338.         return $this->getInstance(reset($this->adminClasses[$class]));
  339.     }
  340.     /**
  341.      * @param string $class
  342.      *
  343.      * @return bool
  344.      *
  345.      * @phpstan-param class-string $class
  346.      */
  347.     public function hasAdminByClass($class)
  348.     {
  349.         return isset($this->adminClasses[$class]) && \count($this->adminClasses[$class]) > 0;
  350.     }
  351.     /**
  352.      * @phpstan-param class-string $class
  353.      *
  354.      * @deprecated since sonata-project/admin-bundle 3.89
  355.      */
  356.     public function hasSingleAdminByClass(string $class): bool
  357.     {
  358.         @trigger_error(sprintf(
  359.             'Method "%s()" is deprecated since sonata-project/admin-bundle 3.89 and will be removed in version 4.0.',
  360.             __METHOD__
  361.         ), \E_USER_DEPRECATED);
  362.         if (!$this->hasAdminByClass($class)) {
  363.             return false;
  364.         }
  365.         return === \count($this->adminClasses[$class]);
  366.     }
  367.     /**
  368.      * Returns an admin class by its Admin code
  369.      * ie : sonata.news.admin.post|sonata.news.admin.comment => return the child class of post.
  370.      *
  371.      * @param string $adminCode
  372.      *
  373.      * @throws AdminCodeNotFoundException
  374.      *
  375.      * @return AdminInterface|false
  376.      */
  377.     public function getAdminByAdminCode($adminCode)
  378.     {
  379.         if (!\is_string($adminCode)) {
  380.             @trigger_error(sprintf(
  381.                 'Passing a non string value as argument 1 for %s() is deprecated since'
  382.                 .' sonata-project/admin-bundle 3.51 and will cause a %s in 4.0.',
  383.                 __METHOD__,
  384.                 \TypeError::class
  385.             ), \E_USER_DEPRECATED);
  386.             return false;
  387.             // NEXT_MAJOR : remove this condition check and declare "string" as type without default value for argument 1
  388.         }
  389.         $codes explode('|'$adminCode);
  390.         $code trim(array_shift($codes));
  391.         $admin $this->getInstance($code);
  392.         foreach ($codes as $code) {
  393.             if (!\in_array($code$this->adminServiceIdstrue)) {
  394.                 @trigger_error(sprintf(
  395.                     'Passing an invalid admin code as argument 1 for %s() is deprecated since'
  396.                     .' sonata-project/admin-bundle 3.50 and will throw an exception in 4.0.',
  397.                     __METHOD__
  398.                 ), \E_USER_DEPRECATED);
  399.                 // NEXT_MAJOR : throw `AdminCodeNotFoundException` instead
  400.             }
  401.             if (!$admin->hasChild($code)) {
  402.                 @trigger_error(sprintf(
  403.                     'Passing an invalid admin hierarchy inside argument 1 for %s() is deprecated since'
  404.                     .' sonata-project/admin-bundle 3.51 and will throw an exception in 4.0.',
  405.                     __METHOD__
  406.                 ), \E_USER_DEPRECATED);
  407.                 // NEXT_MAJOR : remove the previous `trigger_error()` call, uncomment the following exception and declare AdminInterface as return type
  408.                 // throw new AdminCodeNotFoundException(sprintf(
  409.                 //    'Argument 1 passed to %s() must contain a valid admin hierarchy,'
  410.                 //    .' "%s" is not a valid child for "%s"',
  411.                 //    __METHOD__,
  412.                 //    $code,
  413.                 //    $admin->getCode()
  414.                 // ));
  415.                 return false;
  416.             }
  417.             $admin $admin->getChild($code);
  418.         }
  419.         return $admin;
  420.     }
  421.     /**
  422.      * Checks if an admin with a certain admin code exists.
  423.      */
  424.     final public function hasAdminByAdminCode(string $adminCode): bool
  425.     {
  426.         try {
  427.             if (!$this->getAdminByAdminCode($adminCode) instanceof AdminInterface) {
  428.                 // NEXT_MAJOR : remove `if (...instanceof...) { return false; }` as getAdminByAdminCode() will then always throw an \InvalidArgumentException when somethings wrong
  429.                 return false;
  430.             }
  431.         } catch (\InvalidArgumentException $e) {
  432.             return false;
  433.         }
  434.         return true;
  435.     }
  436.     /**
  437.      * @throws AdminClassNotFoundException if there is no admin for the field description target model
  438.      * @throws TooManyAdminClassException  if there is too many admin for the field description target model
  439.      * @throws AdminCodeNotFoundException  if the admin_code option is invalid
  440.      *
  441.      * @return AdminInterface|false|null NEXT_MAJOR: Restrict to AdminInterface
  442.      */
  443.     final public function getAdminByFieldDescription(FieldDescriptionInterface $fieldDescription)
  444.     {
  445.         $adminCode $fieldDescription->getOption('admin_code');
  446.         if (null !== $adminCode) {
  447.             return $this->getAdminByAdminCode($adminCode);
  448.         }
  449.         // NEXT_MAJOR: Remove the check and use `getTargetModel`.
  450.         if (method_exists($fieldDescription'getTargetModel')) {
  451.             /** @var class-string $targetModel */
  452.             $targetModel $fieldDescription->getTargetModel();
  453.         } else {
  454.             $targetModel $fieldDescription->getTargetEntity();
  455.         }
  456.         return $this->getAdminByClass($targetModel);
  457.     }
  458.     /**
  459.      * Returns a new admin instance depends on the given code.
  460.      *
  461.      * @param string $id
  462.      *
  463.      * @throws AdminCodeNotFoundException if the code is not found in admin pool
  464.      *
  465.      * @return AdminInterface
  466.      */
  467.     public function getInstance($id)
  468.     {
  469.         if ('' === $id) {
  470.             throw new \InvalidArgumentException(
  471.                 'Admin code must contain a valid admin reference, empty string given.'
  472.             );
  473.         }
  474.         if (!\in_array($id$this->adminServiceIdstrue)) {
  475.             $msg sprintf('Admin service "%s" not found in admin pool.'$id);
  476.             $shortest = -1;
  477.             $closest null;
  478.             $alternatives = [];
  479.             foreach ($this->adminServiceIds as $adminServiceId) {
  480.                 $lev levenshtein($id$adminServiceId);
  481.                 if ($lev <= $shortest || $shortest 0) {
  482.                     $closest $adminServiceId;
  483.                     $shortest $lev;
  484.                 }
  485.                 if ($lev <= \strlen($adminServiceId) / || false !== strpos($adminServiceId$id)) {
  486.                     $alternatives[$adminServiceId] = $lev;
  487.                 }
  488.             }
  489.             if (null !== $closest) {
  490.                 asort($alternatives);
  491.                 unset($alternatives[$closest]);
  492.                 $msg sprintf(
  493.                     'Admin service "%s" not found in admin pool. Did you mean "%s" or one of those: [%s]?',
  494.                     $id,
  495.                     $closest,
  496.                     implode(', 'array_keys($alternatives))
  497.                 );
  498.             }
  499.             throw new AdminCodeNotFoundException($msg);
  500.         }
  501.         $admin $this->container->get($id);
  502.         if (!$admin instanceof AdminInterface) {
  503.             throw new \InvalidArgumentException(sprintf('Found service "%s" is not a valid admin service'$id));
  504.         }
  505.         return $admin;
  506.     }
  507.     /**
  508.      * NEXT_MAJOR: Remove this method.
  509.      *
  510.      * @deprecated since sonata-project/admin-bundle 3.77.
  511.      *
  512.      * @return ContainerInterface
  513.      */
  514.     public function getContainer()
  515.     {
  516.         if ('sonata_deprecation_mute' !== (\func_get_args()[0] ?? null)) {
  517.             @trigger_error(sprintf(
  518.                 'Method "%s()" is deprecated since sonata-project/admin-bundle 3.77 and will be removed in version 4.0.',
  519.                 __METHOD__
  520.             ), \E_USER_DEPRECATED);
  521.         }
  522.         return $this->container;
  523.     }
  524.     /**
  525.      * NEXT_MAJOR: Remove this method.
  526.      *
  527.      * @deprecated since sonata-project/admin-bundle 3.86, will be dropped in 4.0. Pass $adminGroups as argument 3
  528.      * to the __construct method instead.
  529.      *
  530.      * @phpstan-param array<string, array<string, mixed>> $adminGroups
  531.      * @psalm-param array<string, Group> $adminGroups
  532.      *
  533.      * @return void
  534.      */
  535.     public function setAdminGroups(array $adminGroups)
  536.     {
  537.         if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) {
  538.             @trigger_error(sprintf(
  539.                 'Method "%s()" is deprecated since sonata-project/admin-bundle 3.86 and will be removed in version 4.0.',
  540.                 __METHOD__
  541.             ), \E_USER_DEPRECATED);
  542.         }
  543.         $this->adminGroups $adminGroups;
  544.     }
  545.     /**
  546.      * @return array
  547.      */
  548.     public function getAdminGroups()
  549.     {
  550.         return $this->adminGroups;
  551.     }
  552.     /**
  553.      * NEXT_MAJOR: Remove this method.
  554.      *
  555.      * @deprecated since sonata-project/admin-bundle 3.86, will be dropped in 4.0. Pass $adminGroups as argument 2
  556.      * to the __construct method instead.
  557.      *
  558.      * @return void
  559.      */
  560.     public function setAdminServiceIds(array $adminServiceIds)
  561.     {
  562.         if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) {
  563.             @trigger_error(sprintf(
  564.                 'Method "%s()" is deprecated since sonata-project/admin-bundle 3.86 and will be removed in version 4.0.',
  565.                 __METHOD__
  566.             ), \E_USER_DEPRECATED);
  567.         }
  568.         $this->adminServiceIds $adminServiceIds;
  569.     }
  570.     /**
  571.      * @return string[]
  572.      */
  573.     public function getAdminServiceIds()
  574.     {
  575.         return $this->adminServiceIds;
  576.     }
  577.     /**
  578.      * NEXT_MAJOR: Remove this method.
  579.      *
  580.      * @deprecated since sonata-project/admin-bundle 3.86, will be dropped in 4.0. Pass $adminGroups as argument 4
  581.      * to the __construct method instead.
  582.      *
  583.      * @param array<string, string[]> $adminClasses
  584.      *
  585.      * @phpstan-param array<class-string, string[]> $adminClasses
  586.      *
  587.      * @return void
  588.      */
  589.     public function setAdminClasses(array $adminClasses)
  590.     {
  591.         if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) {
  592.             @trigger_error(sprintf(
  593.                 'Method "%s()" is deprecated since sonata-project/admin-bundle 3.86 and will be removed in version 4.0.',
  594.                 __METHOD__
  595.             ), \E_USER_DEPRECATED);
  596.         }
  597.         $this->adminClasses $adminClasses;
  598.     }
  599.     /**
  600.      * @return array<string, string[]>
  601.      *
  602.      * @phpstan-return array<class-string, string[]>
  603.      */
  604.     public function getAdminClasses()
  605.     {
  606.         return $this->adminClasses;
  607.     }
  608.     /**
  609.      * NEXT_MAJOR: Remove this method.
  610.      *
  611.      * @deprecated since sonata-project/admin-bundle 3.89 and will be removed in 4.0.
  612.      */
  613.     final public function setTemplateRegistry(MutableTemplateRegistryInterface $templateRegistry): void
  614.     {
  615.         if ('sonata_deprecation_mute' !== (\func_get_args()[1] ?? null)) {
  616.             @trigger_error(sprintf(
  617.                 'The "%s()" method is deprecated since version 3.89 and will be removed in 4.0.',
  618.                 __METHOD__,
  619.             ), \E_USER_DEPRECATED);
  620.         }
  621.         $this->templateRegistry $templateRegistry;
  622.     }
  623.     /**
  624.      * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry "sonata.admin.global_template_registry" instead
  625.      *
  626.      * @return void
  627.      */
  628.     public function setTemplates(array $templates)
  629.     {
  630.         // NEXT MAJOR: Remove this line
  631.         $this->templates $templates;
  632.         $this->templateRegistry->setTemplates($templates);
  633.     }
  634.     /**
  635.      * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry "sonata.admin.global_template_registry" instead
  636.      *
  637.      * @return array<string, string>
  638.      */
  639.     public function getTemplates()
  640.     {
  641.         return $this->templateRegistry->getTemplates();
  642.     }
  643.     /**
  644.      * @deprecated since sonata-project/admin-bundle 3.34, will be dropped in 4.0. Use TemplateRegistry "sonata.admin.global_template_registry" instead
  645.      *
  646.      * @param string $name
  647.      *
  648.      * @return string|null
  649.      */
  650.     public function getTemplate($name)
  651.     {
  652.         return $this->templateRegistry->getTemplate($name);
  653.     }
  654.     /**
  655.      * NEXT_MAJOR: Remove this method.
  656.      *
  657.      * @deprecated since sonata-project/admin-bundle 3.83, will be dropped in 4.0.
  658.      *
  659.      * @return string
  660.      */
  661.     public function getTitleLogo()
  662.     {
  663.         @trigger_error(sprintf(
  664.             'The "%s()" method is deprecated since version 3.83 and will be removed in 4.0.'
  665.             .' Use "%s::getLogo()" instead.',
  666.             __METHOD__,
  667.             SonataConfiguration::class
  668.         ), \E_USER_DEPRECATED);
  669.         return $this->titleLogo;
  670.     }
  671.     /**
  672.      * NEXT_MAJOR: Remove this method.
  673.      *
  674.      * @deprecated since sonata-project/admin-bundle 3.83, will be dropped in 4.0.
  675.      *
  676.      * @return string
  677.      */
  678.     public function getTitle()
  679.     {
  680.         @trigger_error(sprintf(
  681.             'The "%s()" method is deprecated since version 3.83 and will be removed in 4.0.'
  682.             .' Use "%s::getTitle()" instead.',
  683.             __METHOD__,
  684.             SonataConfiguration::class
  685.         ), \E_USER_DEPRECATED);
  686.         return $this->title;
  687.     }
  688.     /**
  689.      * NEXT_MAJOR: Remove this method.
  690.      *
  691.      * @deprecated since sonata-project/admin-bundle 3.83, will be dropped in 4.0.
  692.      *
  693.      * @param string $name
  694.      * @param mixed  $default
  695.      *
  696.      * @return mixed
  697.      */
  698.     public function getOption($name$default null)
  699.     {
  700.         @trigger_error(sprintf(
  701.             'The "%s()" method is deprecated since version 3.83 and will be removed in 4.0.'
  702.             .' Use "%s::getOption()" instead.',
  703.             __METHOD__,
  704.             SonataConfiguration::class
  705.         ), \E_USER_DEPRECATED);
  706.         if (isset($this->options[$name])) {
  707.             return $this->options[$name];
  708.         }
  709.         return $default;
  710.     }
  711.     /**
  712.      * @deprecated since sonata-project/admin-bundle 3.82, will be dropped in 4.0. Use Symfony "PropertyAccess" instead.
  713.      */
  714.     public function getPropertyAccessor()
  715.     {
  716.         @trigger_error(sprintf(
  717.             'The "%s" method is deprecated since version 3.82 and will be removed in 4.0.',
  718.             __METHOD__
  719.         ), \E_USER_DEPRECATED);
  720.         if (null === $this->propertyAccessor) {
  721.             $this->propertyAccessor PropertyAccess::createPropertyAccessor();
  722.         }
  723.         return $this->propertyAccessor;
  724.     }
  725. }