Как говорится: в сказке ложь, да в ней намек.
Все делалось не процесса ради а под конкретные нужды. Надеюсь шаблон окажется полезным. Код шаблона под катом.
Все делалось не процесса ради а под конкретные нужды. Надеюсь шаблон окажется полезным. Код шаблона под катом.
- <?php
- /**
- * Cloak is a good thing when we need to hide some public methods and properties.
- */
- abstract class cloak {
- protected $__cloak_method = array();
- protected $__cloak_prop = array();
-
- final function __call($name, $args) {
- if (isset($this->__cloak_method[$name]))
- $this->__cloak_method[$name]();
- }
-
- final function __set($name, $value) {
- if (isset($this->__cloak_prop[$name]))
- $this->__cloak_prop[$name] = $value;
- else
- $this->{$name} = $value;
- }
-
- final function __get($name) {
- if (isset($this->__cloak_prop[$name]))
- return $this->__cloak_prop[$name];
- else
- return $this->{$name};
- }
- }
-
- class necromancer extends cloak {
- function __construct() {
- $this->__cloak_method['zombie_invocation'] = function() {
- print 'Dugonas aldere simopa';
- };
-
- $this->__cloak_prop['inventory'] = array('Kosparov\'s head', 'Rusty knife', 'Necromancer\'s staff');
- $this->__cloak_prop['character'] = 'necromancer';
- }
- }
-
- class inquisitor {
- function inspect_person($person) {
- /**
- * I am going to inspect this heretic.
- */
- $prop = get_object_vars($GLOBALS[$person]);
- if (isset($prop['character']) && in_array($prop['character'], array('necromancer', 'witch')))
- $this->kill($person);
- }
-
- function kill($person) {
- print 'Die, ' . $GLOBALS[$person]->character . "!\n";
- unset($GLOBALS[$person]);
- }
- }
-
- class witch {
- public $character = 'witch';
- public function cast_damnation() {
- print "Let your left hand to dry off!\n";
- }
- }
-
- ///////////////////////////////////////////////////////////////////////////////
- $inquisitor = new inquisitor();
- $necromancer = new necromancer();
- $witch = new witch();
-
- $inquisitor->inspect_person('witch');
- $inquisitor->inspect_person('necromancer');
-
- if(isset($witch))
- $with->cast_damnation();
-
- /**
- * Zombies' time!
- */
- $necromancer->zombie_invocation();
-
- ?>
* This source code was highlighted with Source Code Highlighter.