vendor/sylius/resource-bundle/src/Bundle/DependencyInjection/Compiler/Helper/TargetEntitiesResolver.php line 20

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\ResourceBundle\DependencyInjection\Compiler\Helper;
  12. use Sylius\Component\Resource\Model\ResourceInterface;
  13. final class TargetEntitiesResolver implements TargetEntitiesResolverInterface
  14. {
  15.     public function resolve(array $resourcesConfiguration): array
  16.     {
  17.         $interfaces = [];
  18.         foreach ($resourcesConfiguration as $alias => $configuration) {
  19.             $model $this->getModel($alias$configuration);
  20.             $modelInterfaces class_implements($model) ?: [];
  21.             foreach ($modelInterfaces as $interface) {
  22.                 if ($interface === ResourceInterface::class) {
  23.                     continue;
  24.                 }
  25.                 $interfaces[$interface][] = $model;
  26.             }
  27.         }
  28.         $interfaces array_filter($interfaces, static function (array $classes): bool {
  29.             return count($classes) === 1;
  30.         });
  31.         $interfaces array_map(static function (array $classes): string {
  32.             return current($classes);
  33.         }, $interfaces);
  34.         foreach ($resourcesConfiguration as $alias => $configuration) {
  35.             if (isset($configuration['classes']['interface'])) {
  36.                 $model $this->getModel($alias$configuration);
  37.                 $interface $configuration['classes']['interface'];
  38.                 trigger_deprecation(
  39.                     'sylius/resource-bundle',
  40.                     '1.6',
  41.                     'Specifying the interface for resources is deprecated and will be removed in 2.0. Please rely on auto-discovering interfaces instead. Triggered by resource "%s" with model "%s" and interface "%s".',
  42.                     $alias,
  43.                     $model,
  44.                     $interface,
  45.                 );
  46.                 $interfaces[$interface] = $model;
  47.             }
  48.         }
  49.         return $interfaces;
  50.     }
  51.     private function getModel(string $alias, array $configuration): string
  52.     {
  53.         if (!isset($configuration['classes']['model'])) {
  54.             throw new \InvalidArgumentException(sprintf('Could not get model class from resource "%s".'$alias));
  55.         }
  56.         return $configuration['classes']['model'];
  57.     }
  58. }