1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
namespace Netgen\Bundle\InformationCollectionBundle\ParamConverter; |
5
|
|
|
|
6
|
|
|
use Netgen\InformationCollection\API\Service\InformationCollection; |
7
|
|
|
use Netgen\InformationCollection\API\Value\Collection; |
8
|
|
|
use Netgen\InformationCollection\API\Value\Filter\CollectionId; |
9
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; |
10
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface; |
11
|
|
|
use Symfony\Component\HttpFoundation\Request; |
12
|
|
|
|
13
|
|
|
final class CollectionParamConverter implements ParamConverterInterface |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @var InformationCollection |
17
|
|
|
*/ |
18
|
|
|
protected $informationCollection; |
19
|
|
|
|
20
|
|
|
public function __construct(InformationCollection $informationCollection) |
21
|
|
|
{ |
22
|
|
|
$this->informationCollection = $informationCollection; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Stores the object in the request. |
27
|
|
|
* |
28
|
|
|
* @param ParamConverter $configuration Contains the name, class and options of the object |
29
|
|
|
* |
30
|
|
|
* @return bool True if the object has been successfully set, else false |
31
|
|
|
*/ |
32
|
|
|
public function apply(Request $request, ParamConverter $configuration) |
33
|
|
|
{ |
34
|
|
|
if (!$request->attributes->has('collectionId')) { |
35
|
|
|
return false; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$collectionId = $request->attributes->get('collectionId'); |
39
|
|
|
if (!$collectionId && $configuration->isOptional()) { |
40
|
|
|
return false; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
$request->attributes->set( |
44
|
|
|
$configuration->getName(), $this->informationCollection->getCollection(new CollectionId($collectionId)) |
45
|
|
|
); |
46
|
|
|
|
47
|
|
|
return true; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Checks if the object is supported. |
52
|
|
|
* |
53
|
|
|
* @return bool True if the object is supported, else false |
54
|
|
|
*/ |
55
|
|
|
public function supports(ParamConverter $configuration) |
56
|
|
|
{ |
57
|
|
|
return is_a($configuration->getClass(), Collection::class, true); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|