vendor/api-platform/core/src/Metadata/Property/Factory/InheritedPropertyMetadataFactory.php line 38

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\Core\Metadata\Property\Factory;
  12. use ApiPlatform\Core\Metadata\Property\PropertyMetadata;
  13. use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
  14. /**
  15.  * Get property metadata from eventual child inherited properties.
  16.  *
  17.  * @author Antoine Bluchet <soyuka@gmail.com>
  18.  */
  19. final class InheritedPropertyMetadataFactory implements PropertyMetadataFactoryInterface
  20. {
  21.     private $resourceNameCollectionFactory;
  22.     private $decorated;
  23.     public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactoryPropertyMetadataFactoryInterface $decorated null)
  24.     {
  25.         $this->resourceNameCollectionFactory $resourceNameCollectionFactory;
  26.         $this->decorated $decorated;
  27.     }
  28.     /**
  29.      * {@inheritdoc}
  30.      */
  31.     public function create(string $resourceClassstring $property, array $options = []): PropertyMetadata
  32.     {
  33.         $propertyMetadata $this->decorated $this->decorated->create($resourceClass$property$options) : new PropertyMetadata();
  34.         foreach ($this->resourceNameCollectionFactory->create() as $knownResourceClass) {
  35.             if ($resourceClass === $knownResourceClass) {
  36.                 continue;
  37.             }
  38.             if (is_subclass_of($knownResourceClass$resourceClass)) {
  39.                 $propertyMetadata $this->create($knownResourceClass$property$options);
  40.                 return $propertyMetadata->withChildInherited($knownResourceClass);
  41.             }
  42.         }
  43.         return $propertyMetadata;
  44.     }
  45. }