저는 몇 가지 정적 변수와 함수가있는 PHP 추상 제네릭 클래스를 사용합니다.php 추상화 된 정적 변수는 정적 메서드 호출간에 지속됩니다.
class Generic{
public static $ID;
private static $tableName;
private static $oldTableName;
protected static $DAL;
public static function Init($tableName, $id=null) {
if(self::$tableName)
self::$oldTableName=self::$tableName;
self::$tableName=$tableName;
self::$DAL = new DAL(self::$tableName);
}
public static function RecallTableName(){
if(self::$oldTableName){
self::$tableName=self::$oldTableName;
self::$oldTableName=null;
return true;
}
}
public static function GetProperty($id, $columnName, $whereStatement = "1=1"){
if(!self::$tableName)
return false;
//DO DB STUFF HERE
return; //RETURN WHAT DB CALLS DID HERE
}
}
여러 클래스를 확장하여이 제네릭 클래스에서 상속합니다.
class Part extends Generic {
static function Init($tableName="part",$id = null) {
$return = parent::Init($tableName,$id);
new Part();
return $return;
}
public static function destruct(){
parent::RecallTableName();
}
public function __destruct() {
Part::destruct();
}
public static function GetProperty($id, $columnName, $whereStatement = "1=1") {
self::Init();
return parent::GetProperty($id, $columnName, $whereStatement);
}
}
class System extends Generic {
static function Init($tableName="system",$id = null) {
$return = parent::Init($tableName,$id);
new System();
return $return;
}
public static function destruct(){
parent::RecallTableName();
}
public function __destruct() {
Part::destruct();
}
public static function GetProperty($id, $columnName, $whereStatement = "1=1") {
self::Init();
return parent::GetProperty($id, $columnName, $whereStatement);
}
public static function GetInventory($PartManageIDToCheck)
{
return Part::GetInventory($PartManageIDToCheck);
}
}
이렇게하면 자식에 대한 메서드 호출을 구현할 때 자식의 죽음을 연결할 수 있습니다. 더 나아가, 나는 호출 할 수
System::GetInventory(1)
이됩니다
이 - 1 Generic::$tableName
에 Generic
에 저장 "시스템"Init()
를 호출합니다.
2 - 중첩 된 형제 차례로 다음 문제없이 Generic::$tableName
이 모든 작품 Generic::$tableName
Generic::$oldTableName
에 저장 "부분을 이동하는 Init()
Generic
에 호출 (파트) Cenerate 그러나, 나는 다시 다시 두 아이를 사용하는 경우. 그것은 떨어져 떨어진다.
System::GetProperty(1, "ID");
Part::GetProperty(3, "ID");
Generic::$tableName == "system"
것을 Part::GetProperty(3, "ID");
가 호출 될 때, 그래서 다시 다시 두 사람은 어떻게 든 지속 일반 수 있습니다 사용.
이 문제를 해결하는 방법에 대해 알고 싶습니다.