1<?php
2
3declare(strict_types=1);
4
5namespace JMS\Serializer\EventDispatcher;
6
7use JMS\Serializer\Context;
8use JMS\Serializer\VisitorInterface;
9
10class Event
11{
12    /**
13     * @var bool Whether no further event listeners should be triggered
14     */
15    private $propagationStopped = false;
16
17    /**
18     * @var array
19     */
20    protected $type;
21
22    /**
23     * @var Context
24     */
25    private $context;
26
27    public function __construct(Context $context, array $type)
28    {
29        $this->context = $context;
30        $this->type = $type;
31    }
32
33    public function getVisitor(): VisitorInterface
34    {
35        return $this->context->getVisitor();
36    }
37
38    public function getContext(): Context
39    {
40        return $this->context;
41    }
42
43    public function getType(): array
44    {
45        return $this->type;
46    }
47
48    /**
49     * Returns whether further event listeners should be triggered.
50     *
51     * @see Event::stopPropagation()
52     *
53     * @return bool Whether propagation was already stopped for this event
54     */
55    public function isPropagationStopped(): bool
56    {
57        return $this->propagationStopped;
58    }
59
60    /**
61     * Stops the propagation of the event to further event listeners.
62     *
63     * If multiple event listeners are connected to the same event, no
64     * further event listener will be triggered once any trigger calls
65     * stopPropagation().
66     */
67    public function stopPropagation(): void
68    {
69        $this->propagationStopped = true;
70    }
71}
72