components-web-app /
api-components-bundle
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the Silverback API Components Bundle Project |
||
| 5 | * |
||
| 6 | * (c) Daniel West <[email protected]> |
||
| 7 | * |
||
| 8 | * For the full copyright and license information, please view the LICENSE |
||
| 9 | * file that was distributed with this source code. |
||
| 10 | */ |
||
| 11 | |||
| 12 | declare(strict_types=1); |
||
| 13 | |||
| 14 | namespace Silverback\ApiComponentsBundle\Metadata\Provider; |
||
| 15 | |||
| 16 | use ApiPlatform\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface; |
||
| 17 | use Silverback\ApiComponentsBundle\Entity\Core\PageDataInterface; |
||
| 18 | use Silverback\ApiComponentsBundle\Metadata\Factory\PageDataMetadataFactoryInterface; |
||
| 19 | use Silverback\ApiComponentsBundle\Metadata\PageDataMetadata; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @author Daniel West <[email protected]> |
||
| 23 | */ |
||
| 24 | class PageDataMetadataProvider |
||
| 25 | { |
||
| 26 | private ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory; |
||
| 27 | private PageDataMetadataFactoryInterface $pageDataMetadataFactory; |
||
| 28 | |||
| 29 | public function __construct( |
||
| 30 | ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, |
||
| 31 | PageDataMetadataFactoryInterface $pageDataMetadataFactory |
||
| 32 | ) { |
||
| 33 | $this->resourceNameCollectionFactory = $resourceNameCollectionFactory; |
||
| 34 | $this->pageDataMetadataFactory = $pageDataMetadataFactory; |
||
| 35 | } |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @return PageDataMetadata[]|iterable |
||
| 39 | */ |
||
| 40 | public function createAll(): iterable |
||
| 41 | { |
||
| 42 | foreach ($this->resourceNameCollectionFactory->create() as $pageDataResourceClass) { |
||
| 43 | $reflectionClass = new \ReflectionClass($pageDataResourceClass); |
||
| 44 | if (!$reflectionClass->implementsInterface(PageDataInterface::class)) { |
||
| 45 | continue; |
||
| 46 | } |
||
| 47 | |||
| 48 | yield $this->pageDataMetadataFactory->create($pageDataResourceClass); |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 49 | } |
||
| 50 | } |
||
| 51 | } |
||
| 52 |