Total Complexity | 5 |
Total Lines | 45 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
18 | class ChangeUrl implements MutatorInterface |
||
19 | { |
||
20 | /** @var Request */ |
||
21 | private $request; |
||
22 | /** @var UrlGeneratorInterface */ |
||
23 | private $router; |
||
24 | /** @var bool */ |
||
25 | private $changeUrl = true; |
||
26 | |||
27 | public function __construct(RequestStack $requestStack, UrlGeneratorInterface $router) |
||
28 | { |
||
29 | $this->router = $router; |
||
30 | $this->request = $requestStack->getMainRequest(); |
||
31 | } |
||
32 | |||
33 | public function mutate(Handler $ajax): Handler |
||
34 | { |
||
35 | if (false === $this->changeUrl) { |
||
36 | return $ajax; |
||
37 | } |
||
38 | |||
39 | $ajax->changeUrl( |
||
40 | $this->router->generate( |
||
41 | $this->request->attributes->get('_route'), |
||
42 | array_merge( |
||
43 | $this->request->attributes->get('_route_params'), |
||
44 | $this->request->query->all(), |
||
45 | $this->getFragment() |
||
46 | ) |
||
47 | ) |
||
48 | ); |
||
49 | |||
50 | return $ajax; |
||
51 | } |
||
52 | |||
53 | public function doNotChangeUrl(): self |
||
54 | { |
||
55 | $this->changeUrl = false; |
||
56 | |||
57 | return $this; |
||
58 | } |
||
59 | |||
60 | private function getFragment(): array |
||
63 | } |
||
64 | } |
||
65 |