Login   Register  
PHP Classes
elePHPant
Icontem

File: masterClass.class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ben A. Noone  >  Master Class SubClass  >  masterClass.class.php  >  Download  
File: masterClass.class.php
Role: Class source
Content type: text/plain
Description: Abstract Class MasterClass
Class: Master Class SubClass
Create and manage hierarchies of classes
Author: By
Last change: removed file specific code
Date: 3 months ago
Size: 1,608 bytes
 

Contents

Class file image Download
<?php
/*
    masterClass
    Extendable template class MasterClass
    Enables Class Hierarchy without comprimising structure
    Requires: subclass

*/
/*****************************************/

abstract class masterClass{
    public 
$subclasses = array();
    private 
$subclassCon = array();

    public function 
__call($function$arguments){
        foreach(
$this->subclasses as $subclass){
            if(
method_exists($subclass$function)) break;
        }
        
$class $this->getInstance($subclass);
        return 
call_user_func_array(array(&$class$function), $arguments);
    }

    public function &
__get($variable){
        if(
in_array($variable,$this->subclasses))return $this->getInstance($variable);
        foreach(
$this->subclasses as $subclass){
            if(
in_array($variableget_class_vars($subclass))) break;
        }
        
$class $this->getInstance($subclass);
        return 
$class->$variable;
    }

    public function 
__set($variable$value){
        
$match false;
        foreach(
$this->subclasses as $subclass){
            if(
in_array($variableget_class_vars($subclass))) $match $subclass;
        }
        if(
$match != false$class $this->getInstance($match);
        else 
$class = &$this;
        
$class->$variable $value;
    }

    private function &
getInstance($subclass){
        if(isset(
$this->subclassCon[$subclass])) return $this->subclassCon[$subclass];
        
$this->subclassCon[$subclass] = $this->$subclass = new $subclass($this);
        return 
$this->subclassCon[$subclass];
    }
}
?>