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

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 $resources): array
  16.     {
  17.         $interfaces = [];
  18.         foreach ($resources as $alias => $configuration) {
  19.             $model $this->getModel($alias$configuration);
  20.             foreach (class_implements($model) as $interface) {
  21.                 if ($interface === ResourceInterface::class) {
  22.                     continue;
  23.                 }
  24.                 $interfaces[$interface][] = $model;
  25.             }
  26.         }
  27.         $interfaces array_filter($interfaces, function (array $classes): bool {
  28.             return count($classes) === 1;
  29.         });
  30.         $interfaces array_map(function (array $classes): string {
  31.             return (string) current($classes);
  32.         }, $interfaces);
  33.         foreach ($resources as $alias => $configuration) {
  34.             if (isset($configuration['classes']['interface'])) {
  35.                 $model $this->getModel($alias$configuration);
  36.                 $interface $configuration['classes']['interface'];
  37.                 @trigger_error(
  38.                     sprintf(
  39.                         'Specifying interface for resources is deprecated since ResourceBundle v1.6 and will be removed in v2.0. ' .
  40.                         'Please rely on autodiscovering entity interfaces instead. ' .
  41.                         'Triggered by resource "%s" with model "%s" and interface "%s".',
  42.                         $alias,
  43.                         $model,
  44.                         $interface
  45.                     ),
  46.                     \E_USER_DEPRECATED
  47.                 );
  48.                 $interfaces[$interface] = $model;
  49.             }
  50.         }
  51.         return $interfaces;
  52.     }
  53.     private function getModel(string $alias, array $configuration): string
  54.     {
  55.         if (!isset($configuration['classes']['model'])) {
  56.             throw new \InvalidArgumentException(sprintf('Could not get model class from resource "%s".'$alias));
  57.         }
  58.         return $configuration['classes']['model'];
  59.     }
  60. }