-
-
Notifications
You must be signed in to change notification settings - Fork 857
/
PropertyInfoPropertyNameCollectionFactory.php
51 lines (43 loc) · 1.52 KB
/
PropertyInfoPropertyNameCollectionFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/*
* This file is part of the API Platform project.
*
* (c) Kévin Dunglas <dunglas@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace ApiPlatform\Core\Bridge\Symfony\PropertyInfo\Metadata\Property;
use ApiPlatform\Core\Exception\RuntimeException;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Property\PropertyNameCollection;
use Symfony\Component\PropertyInfo\PropertyInfoExtractorInterface;
/**
* PropertyInfo collection loader.
*
* This is not a decorator on purpose because it should always have the top priority.
*
* @author Kévin Dunglas <dunglas@gmail.com>
*/
final class PropertyInfoPropertyNameCollectionFactory implements PropertyNameCollectionFactoryInterface
{
private $propertyInfo;
public function __construct(PropertyInfoExtractorInterface $propertyInfo)
{
$this->propertyInfo = $propertyInfo;
}
/**
* {@inheritdoc}
*
* @throws RuntimeException
*/
public function create(string $resourceClass, array $options = []): PropertyNameCollection
{
$properties = $this->propertyInfo->getProperties($resourceClass, $options);
if (null === $properties) {
throw new RuntimeException(sprintf('There is no PropertyInfo extractor supporting the class "%s".', $resourceClass));
}
return new PropertyNameCollection($properties);
}
}