Conditions | 5 |
Paths | 3 |
Total Lines | 19 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
33 | public function onPreValidate(ViewEvent $event): void |
||
34 | { |
||
35 | $request = $event->getRequest(); |
||
36 | $data = $request->attributes->get('data'); |
||
37 | if ( |
||
38 | empty($data) || |
||
39 | !$data instanceof Route || |
||
40 | 'generate' !== $request->attributes->get('_api_collection_operation_name') |
||
41 | ) { |
||
42 | return; |
||
43 | } |
||
44 | |||
45 | $page = $data->getPageData() ?? $data->getPage(); |
||
46 | if (!$page) { |
||
47 | throw new BadRequestHttpException('You must submit a page or pageData to generate a route.'); |
||
48 | } |
||
49 | |||
50 | $route = $this->routeGenerator->createFromPage($page, $data); |
||
51 | $request->attributes->set('data', $route); |
||
52 | } |
||
54 |