From b276ac7f6a94d36bcafd8ef08ff92f3ef21d451e Mon Sep 17 00:00:00 2001 From: Fabian de Boer Date: Sat, 18 Jul 2026 11:56:54 +0200 Subject: [PATCH] made ZapHandler library --- docs/ZapHandler.md | 16 ++++++++++++++++ lib/ZAPController.class.php | 3 +++ lib/ZAPDisplay.class.php | 2 +- lib/ZAPHandler.interface.php | 12 ++++++++++++ lib/ZAPHome.class.php | 2 +- lib/ZAPZap.class.php | 2 +- 6 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 docs/ZapHandler.md create mode 100644 lib/ZAPHandler.interface.php diff --git a/docs/ZapHandler.md b/docs/ZapHandler.md new file mode 100644 index 0000000..b6c6e9a --- /dev/null +++ b/docs/ZapHandler.md @@ -0,0 +1,16 @@ +# ZAPHandler Interface + +| File | Change | +|------|--------| +| **`lib/ZAPHandler.interface.php`** | **Created** — defines `ZAPHandler` interface with `public function getContent()` | +| **`lib/ZAPHome.class.php`** | Added `implements ZAPHandler` | +| **`lib/ZAPDisplay.class.php`** | Added `implements ZAPHandler` | +| **`lib/ZAPZap.class.php`** | Added `implements ZAPHandler` | +| **`lib/ZAPController.class.php`** | Added `instanceof ZAPHandler` guard inside `fetch()` before calling `getContent()` | + +### How it works + +- Any class named `ZAP{Mode}` in `lib/` is autoloaded and instantiated by `ZAPController` +- The controller now checks `$this->action instanceof ZAPHandler` **before** calling `getContent()` +- If a handler forgets to implement the interface, you get a clear `die()` message instead of a cryptic runtime error +- The interface file uses the `.interface.php` naming convention, which the existing autoloader already handles (it checks `.interface.php` first, then `.class.php`) \ No newline at end of file diff --git a/lib/ZAPController.class.php b/lib/ZAPController.class.php index 27214f1..115b416 100755 --- a/lib/ZAPController.class.php +++ b/lib/ZAPController.class.php @@ -35,6 +35,9 @@ class ZAPController { * @return string content */ public function fetch() { + if (!($this->action instanceof ZAPHandler)) { + die('Handler does not implement ZAPHandler interface'); + } return $this->action->getContent(); } } diff --git a/lib/ZAPDisplay.class.php b/lib/ZAPDisplay.class.php index a1398ab..2d1ef71 100755 --- a/lib/ZAPDisplay.class.php +++ b/lib/ZAPDisplay.class.php @@ -2,7 +2,7 @@ /** * Class is responsible for starting up ZAP machine */ -class ZAPDisplay { +class ZAPDisplay implements ZAPHandler { /** * Template file */ diff --git a/lib/ZAPHandler.interface.php b/lib/ZAPHandler.interface.php new file mode 100644 index 0000000..4f38e1a --- /dev/null +++ b/lib/ZAPHandler.interface.php @@ -0,0 +1,12 @@ +