1 | <?php |
||
15 | class DateTimeParamConverter implements ParamConverterInterface |
||
16 | { |
||
17 | /** |
||
18 | * {@inheritdoc} |
||
19 | * |
||
20 | * @throws NotFoundHttpException When invalid date given |
||
21 | */ |
||
22 | 5 | public function apply(Request $request, ParamConverter $configuration) |
|
23 | { |
||
24 | 5 | $param = $configuration->getName(); |
|
25 | 5 | if (!$request->attributes->has($param)) { |
|
26 | 1 | return false; |
|
27 | } |
||
28 | |||
29 | 4 | $value = $request->attributes->get($param); |
|
30 | 4 | if (!$value && $configuration->isOptional()) { |
|
31 | 1 | return false; |
|
32 | } |
||
33 | |||
34 | 3 | $request->attributes->set($param, |
|
35 | 3 | $this->getDateTime($configuration, $value, $param)); |
|
36 | |||
37 | 1 | return true; |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param ParamConverter $configuration |
||
42 | * @param string $value |
||
43 | * @param string $param |
||
44 | * |
||
45 | * @return \DateTime |
||
46 | */ |
||
47 | 3 | protected function getDateTime(ParamConverter $configuration, $value, $param) |
|
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | 1 | public function supports(ParamConverter $configuration) |
|
72 | } |
||
73 |