Event.php 2.1 KB

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