+++ /dev/null
-<?php
-
-namespace wcf\system\event;
-
-/**
- * Indicates that the event may be cancelled, stopping the action from happening.
- *
- * @author Tim Duesterhus
- * @copyright 2001-2021 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package WoltLabSuite\Core\System\Event
- * @since 5.5
- */
-interface ICancelableEvent extends IEvent
-{
- /**
- * Cancels the event.
- */
- public function cancel(): void;
-
- /**
- * Returns whether the event is cancelled.
- */
- public function isCancelled(): bool;
-}
--- /dev/null
+<?php
+
+namespace wcf\system\event;
+
+/**
+ * Event listeners handling interruptable events may indicate that the code path
+ * of the action that fired the event should not proceed.
+ *
+ * As an example, this may be used to prevent a successful login if an interruptable
+ * event is being fired when a user logs in.
+ *
+ * @author Tim Duesterhus
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Event
+ * @since 5.5
+ */
+interface IInterruptableEvent extends IEvent
+{
+ /**
+ * Indicates that the code path that fired this event should not proceed after
+ * this event was handled. The caller is responsible to check the status with
+ * `defaultPrevented()`.
+ *
+ * All event listeners will be invoked, even if an event listener in the middle
+ * of the stack calls `preventDefault()`.
+ */
+ public function preventDefault(): void;
+
+ /**
+ * Returns whether preventDefault() was called.
+ */
+ public function defaultPrevented(): bool;
+}
+++ /dev/null
-<?php
-
-namespace wcf\system\event;
-
-/**
- * Default implementation for cancelable events.
- *
- * @author Tim Duesterhus
- * @copyright 2001-2021 WoltLab GmbH
- * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @package WoltLabSuite\Core\System\Event
- * @since 5.5
- */
-trait TCancelableEvent
-{
- /**
- * @var bool
- */
- private $isCancelled = false;
-
- /**
- * @see ICancelableEvent::cancel()
- */
- public function cancel(): void
- {
- $this->isCancelled = true;
- }
-
- /**
- * @see ICancelableEvent::isCancelled()
- */
- public function isCancelled(): bool
- {
- return $this->isCancelled;
- }
-}
--- /dev/null
+<?php
+
+namespace wcf\system\event;
+
+/**
+ * Default implementation for interruptable events.
+ *
+ * @author Tim Duesterhus
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core\System\Event
+ * @since 5.5
+ */
+trait TInterruptableEvent
+{
+ /**
+ * @var bool
+ */
+ private $defaultPrevented = false;
+
+ /**
+ * @see IInterruptableEvent::preventDefault()
+ */
+ public function preventDefault(): void
+ {
+ $this->defaultPrevented = true;
+ }
+
+ /**
+ * @see IInterruptableEvent::defaultPrevented()
+ */
+ public function defaultPrevented(): bool
+ {
+ return $this->defaultPrevented;
+ }
+}