vendor/api-platform/core/src/Metadata/Resource/Factory/ExtractorResourceNameCollectionFactory.php line 46

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the API Platform project.
  4.  *
  5.  * (c) Kévin Dunglas <dunglas@gmail.com>
  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 ApiPlatform\Metadata\Resource\Factory;
  12. use ApiPlatform\Exception\InvalidArgumentException;
  13. use ApiPlatform\Metadata\Extractor\ResourceExtractorInterface;
  14. use ApiPlatform\Metadata\Resource\ResourceNameCollection;
  15. /**
  16.  * Creates a resource name collection from {@see ApiResource} configuration files.
  17.  *
  18.  * @author Kévin Dunglas <dunglas@gmail.com>
  19.  * @author Antoine Bluchet <soyuka@gmail.com>
  20.  */
  21. final class ExtractorResourceNameCollectionFactory implements ResourceNameCollectionFactoryInterface
  22. {
  23.     private $extractor;
  24.     private $decorated;
  25.     public function __construct(ResourceExtractorInterface $extractorResourceNameCollectionFactoryInterface $decorated null)
  26.     {
  27.         $this->extractor $extractor;
  28.         $this->decorated $decorated;
  29.     }
  30.     /**
  31.      * {@inheritdoc}
  32.      *
  33.      * @throws InvalidArgumentException
  34.      */
  35.     public function create(): ResourceNameCollection
  36.     {
  37.         $classes = [];
  38.         if ($this->decorated) {
  39.             foreach ($this->decorated->create() as $resourceClass) {
  40.                 $classes[$resourceClass] = true;
  41.             }
  42.         }
  43.         foreach ($this->extractor->getResources() as $resourceClass => $resource) {
  44.             $classes[$resourceClass] = true;
  45.         }
  46.         return new ResourceNameCollection(array_keys($classes));
  47.     }
  48. }