From 506ee49135ffb2658ccf2e71caa9ed352526a834 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 17 Feb 2021 11:24:42 +0100 Subject: [PATCH] Add interfaces and traits for reusable events --- .../system/event/ICancelableEvent.class.php | 25 +++++++++++++ .../files/lib/system/event/IEvent.class.php | 16 +++++++++ .../system/event/TCancelableEvent.class.php | 36 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 wcfsetup/install/files/lib/system/event/ICancelableEvent.class.php create mode 100644 wcfsetup/install/files/lib/system/event/IEvent.class.php create mode 100644 wcfsetup/install/files/lib/system/event/TCancelableEvent.class.php diff --git a/wcfsetup/install/files/lib/system/event/ICancelableEvent.class.php b/wcfsetup/install/files/lib/system/event/ICancelableEvent.class.php new file mode 100644 index 0000000000..b01acae89c --- /dev/null +++ b/wcfsetup/install/files/lib/system/event/ICancelableEvent.class.php @@ -0,0 +1,25 @@ + + * @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; +} diff --git a/wcfsetup/install/files/lib/system/event/IEvent.class.php b/wcfsetup/install/files/lib/system/event/IEvent.class.php new file mode 100644 index 0000000000..dce3528d7a --- /dev/null +++ b/wcfsetup/install/files/lib/system/event/IEvent.class.php @@ -0,0 +1,16 @@ + + * @package WoltLabSuite\Core\System\Event + * @since 5.5 + */ +interface IEvent +{ +} diff --git a/wcfsetup/install/files/lib/system/event/TCancelableEvent.class.php b/wcfsetup/install/files/lib/system/event/TCancelableEvent.class.php new file mode 100644 index 0000000000..9497d562c7 --- /dev/null +++ b/wcfsetup/install/files/lib/system/event/TCancelableEvent.class.php @@ -0,0 +1,36 @@ + + * @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; + } +} -- 2.20.1