made ZapHandler library
This commit is contained in:
parent
d185a26f87
commit
b276ac7f6a
6 changed files with 34 additions and 3 deletions
16
docs/ZapHandler.md
Normal file
16
docs/ZapHandler.md
Normal file
|
|
@ -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`)
|
||||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* Class is responsible for starting up ZAP machine
|
||||
*/
|
||||
class ZAPDisplay {
|
||||
class ZAPDisplay implements ZAPHandler {
|
||||
/**
|
||||
* Template file
|
||||
*/
|
||||
|
|
|
|||
12
lib/ZAPHandler.interface.php
Normal file
12
lib/ZAPHandler.interface.php
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
/**
|
||||
* Interface for ZAP mode handlers.
|
||||
* All ZAP handler classes must implement this interface.
|
||||
*/
|
||||
interface ZAPHandler {
|
||||
/**
|
||||
* Renders and returns the content for this mode.
|
||||
* @return string
|
||||
*/
|
||||
public function getContent();
|
||||
}
|
||||
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* Index class
|
||||
*/
|
||||
class ZAPHome {
|
||||
class ZAPHome implements ZAPHandler {
|
||||
/**
|
||||
* Template file prefix
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
/**
|
||||
* ZAP factory
|
||||
*/
|
||||
class ZAPZap {
|
||||
class ZAPZap implements ZAPHandler {
|
||||
private $tpl = '';
|
||||
private $folder;
|
||||
private $height;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue