1<?php
2
3/*
4 * This file is part of Composer.
5 *
6 * (c) Nils Adermann <naderman@naderman.de>
7 *     Jordi Boggiano <j.boggiano@seld.be>
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12
13namespace Composer\EventDispatcher;
14
15/**
16 * The base event class
17 *
18 * @author Nils Adermann <naderman@naderman.de>
19 */
20class Event
21{
22    /**
23     * @var string This event's name
24     */
25    protected $name;
26
27    /**
28     * @var array Arguments passed by the user, these will be forwarded to CLI script handlers
29     */
30    protected $args;
31
32    /**
33     * @var array Flags usable in PHP script handlers
34     */
35    protected $flags;
36
37    /**
38     * @var bool Whether the event should not be passed to more listeners
39     */
40    private $propagationStopped = false;
41
42    /**
43     * Constructor.
44     *
45     * @param string $name  The event name
46     * @param array  $args  Arguments passed by the user
47     * @param array  $flags Optional flags to pass data not as argument
48     */
49    public function __construct($name, array $args = array(), array $flags = array())
50    {
51        $this->name = $name;
52        $this->args = $args;
53        $this->flags = $flags;
54    }
55
56    /**
57     * Returns the event's name.
58     *
59     * @return string The event name
60     */
61    public function getName()
62    {
63        return $this->name;
64    }
65
66    /**
67     * Returns the event's arguments.
68     *
69     * @return array The event arguments
70     */
71    public function getArguments()
72    {
73        return $this->args;
74    }
75
76    /**
77     * Returns the event's flags.
78     *
79     * @return array The event flags
80     */
81    public function getFlags()
82    {
83        return $this->flags;
84    }
85
86    /**
87     * Checks if stopPropagation has been called
88     *
89     * @return bool Whether propagation has been stopped
90     */
91    public function isPropagationStopped()
92    {
93        return $this->propagationStopped;
94    }
95
96    /**
97     * Prevents the event from being passed to further listeners
98     */
99    public function stopPropagation()
100    {
101        $this->propagationStopped = true;
102    }
103}
104