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 @@ +