<?php
class CallBackend extends CallBackendClass {
public function __construct() {
$this->CallBackendClassPath = dirname(__FILE__)."/api/";
$this->Base = $this;
}
}
class CallBackendClass {
protected $Base;
protected $CallBackendClassPath;
protected $CallBackendClassCache = array();
//Default constructor
public function __get($Name) {
return $this->CallBackendBuilder($Name);
}
//(Re)build with custom Constructor
public function __call($Name,$Arguments) {
return $this->CallBackendBuilder($Name,$Arguments);
}
//Delete
public function __unset($Name) {
if(isset($this->CallBackendClassCache[$Name])) unset($this->CallBackendClassCache[$Name]);
}
private function CallBackendBuilder($Name,$Arguments=false) {
//Preliminary checks
if(!$Arguments && isset($this->CallBackendClassCache[$Name])) return $this->CallBackendClassCache[$Name];
if(!is_dir($this->CallBackendClassPath.$Name)) return NULL;
require_once $this->CallBackendClassPath.$Name."/".$Name.".php";
//Initialize class
$reflect = new ReflectionClass("Call_".$Name);
//Add values
$this->CallBackendClassCache[$Name] = $Arguments ? $reflect->newInstanceArgs($Arguments) : $reflect->newInstance();
$this->CallBackendClassCache[$Name]->CallBackendClassPath = $this->CallBackendClassPath.$Name."/";
$this->CallBackendClassCache[$Name]->Base = $this->Base;
//Return
return $this->CallBackendClassCache[$Name];
}
}
?>