1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace CalendarBundle\Controller; |
6
|
|
|
|
7
|
|
|
use CalendarBundle\CalendarEvents; |
8
|
|
|
use CalendarBundle\Event\CalendarEvent; |
9
|
|
|
use CalendarBundle\Serializer\SerializerInterface; |
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
11
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
12
|
|
|
use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; |
13
|
|
|
use Symfony\Component\HttpFoundation\Request; |
14
|
|
|
use Symfony\Component\HttpFoundation\Response; |
15
|
|
|
|
16
|
|
|
class CalendarController extends AbstractController |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var SerializerInterface |
20
|
|
|
*/ |
21
|
|
|
protected $serializer; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var EventDispatcherInterface |
25
|
|
|
*/ |
26
|
|
|
protected $eventDispatcher; |
27
|
|
|
|
28
|
|
|
public function __construct( |
29
|
|
|
EventDispatcherInterface $eventDispatcher, |
30
|
|
|
SerializerInterface $serializer |
31
|
|
|
) { |
32
|
|
|
if (class_exists(LegacyEventDispatcherProxy::class)) { |
33
|
|
|
$eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher); |
34
|
|
|
} |
35
|
|
|
$this->eventDispatcher = $eventDispatcher; |
36
|
|
|
$this->serializer = $serializer; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function loadAction(Request $request): Response |
40
|
|
|
{ |
41
|
|
|
$start = new \DateTime($request->get('start')); |
42
|
|
|
$end = new \DateTime($request->get('end')); |
43
|
|
|
$filters = $request->get('filters', '{}'); |
44
|
|
|
$filters = \is_array($filters) ? $filters : json_decode($filters, true); |
45
|
|
|
|
46
|
|
|
$event = $this->dispatchWithBC( |
47
|
|
|
new CalendarEvent($start, $end, $filters), |
48
|
|
|
CalendarEvents::SET_DATA |
49
|
|
|
); |
50
|
|
|
$content = $this->serializer->serialize($event->getEvents()); |
51
|
|
|
|
52
|
|
|
$response = new Response(); |
53
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
54
|
|
|
$response->setContent($content); |
55
|
|
|
$response->setStatusCode(empty($content) ? Response::HTTP_NO_CONTENT : Response::HTTP_OK); |
56
|
|
|
|
57
|
|
|
return $response; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
private function dispatchWithBC($event, string $eventName) |
61
|
|
|
{ |
62
|
|
|
if (class_exists(LegacyEventDispatcherProxy::class)) { |
63
|
|
|
return $this->eventDispatcher->dispatch($event, $eventName); |
|
|
|
|
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
return $this->eventDispatcher->dispatch($eventName, $event); |
|
|
|
|
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.