mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-06-30 21:45:01 +03:00
Поддержка наследований классов движка плагинами через $aInherits
This commit is contained in:
parent
f356566968
commit
0feaef7197
|
@ -637,5 +637,36 @@ function __autoload($sClassName) {
|
|||
require_once($sFileClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Загрузка цепочки наследуемых классов
|
||||
*/
|
||||
if (preg_match("/^Plugin(\w+)\_Inherits\_([\w\_]+)$/i",$sClassName,$aMatch)) {
|
||||
$sPlugin=$aMatch[1];
|
||||
$sInheritClass=$aMatch[2];
|
||||
$sParentClass=Engine::getInstance()->Plugin_GetParentInherit($sInheritClass);
|
||||
class_alias($sParentClass,$sClassName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Загрузка класса экшена
|
||||
*/
|
||||
if (preg_match("/^Action(\w+)$/i",$sClassName,$aMatch)) {
|
||||
$sFileClass=Config::get('path.root.server').'/classes/actions/'.$sClassName.'.class.php';
|
||||
if (file_exists($sFileClass)) {
|
||||
require_once($sFileClass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Загрузка класса экшена плагина
|
||||
*/
|
||||
if (preg_match("/^Plugin(\w+)\_Action(\w+)$/i",$sClassName,$aMatch)) {
|
||||
$sFileClass=Config::get('path.root.server').'/plugins/'.strtolower($aMatch[1]).'/classes/actions/Action'.$aMatch[2].'.class.php';
|
||||
if (file_exists($sFileClass)) {
|
||||
require_once($sFileClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -38,6 +38,12 @@ abstract class Plugin extends Object {
|
|||
* @var array
|
||||
*/
|
||||
protected $aDelegates=array();
|
||||
/**
|
||||
* Массив наследуемых классов плагина
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $aInherits=array();
|
||||
|
||||
public function __construct() {
|
||||
|
||||
|
@ -96,10 +102,25 @@ abstract class Plugin extends Object {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(is_array($this->aInherits) and count($this->aInherits)) {
|
||||
foreach ($this->aInherits as $sObjectName=>$aParams) {
|
||||
if(is_array($aParams) and count($aParams)) {
|
||||
foreach ($aParams as $sFrom=>$sTo) {
|
||||
if (is_int($sFrom)) {
|
||||
$sFrom=$sTo;
|
||||
$sTo=null;
|
||||
}
|
||||
$this->DelegateWrapper($sObjectName,$sFrom,$sTo);
|
||||
$this->Plugin_Inherit($sFrom,$sTo,get_class($this));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function DelegateWrapper($sObjectName,$sFrom,$sTo=null) {
|
||||
public function DelegateWrapper($sObjectName,$sFrom,&$sTo=null) {
|
||||
/**
|
||||
* Если не указан делегат TO, считаем, что делегатом является
|
||||
* одноименный объект текущего плагина
|
||||
|
|
|
@ -406,4 +406,10 @@ if (!function_exists('array_intersect_key')) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('class_alias')) {
|
||||
function class_alias($original, $alias) {
|
||||
eval('abstract class ' . $alias . ' extends ' . $original . ' {}');
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -58,6 +58,13 @@ class ModulePlugin extends Module {
|
|||
'template' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
* Стек наследований
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $aInherits=array();
|
||||
|
||||
/**
|
||||
* Инициализация модуля
|
||||
*
|
||||
|
@ -319,6 +326,40 @@ class ModulePlugin extends Module {
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Добавляет в стек наследника класса
|
||||
*
|
||||
* @param string $sFrom
|
||||
* @param string $sTo
|
||||
* @param string $sSign
|
||||
*/
|
||||
public function Inherit($sFrom,$sTo,$sSign=__CLASS__) {
|
||||
if(!is_string($sSign) or !strlen($sSign)) return null;
|
||||
if(!$sFrom or !$sTo) return null;
|
||||
|
||||
$this->aInherits[trim(strtolower($sFrom))]['items'][]=array(
|
||||
'inherit'=>trim($sTo),
|
||||
'sign'=>$sSign
|
||||
);
|
||||
$this->aInherits[trim(strtolower($sFrom))]['position']=count($this->aInherits[trim(strtolower($sFrom))]['items'])-1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Получает следующего родителя у наследника.
|
||||
* ВНИМАНИЕ! Данный метод нужно вызвать только из __autoload()
|
||||
*
|
||||
* @param unknown_type $sFrom
|
||||
* @return unknown
|
||||
*/
|
||||
public function GetParentInherit($sFrom) {
|
||||
$sKey=strtolower($sFrom);
|
||||
if (!isset($this->aInherits[$sKey]['items']) or count($this->aInherits[$sKey]['items'])<=1 or $this->aInherits[$sKey]['position']<1) {
|
||||
return $sFrom;
|
||||
}
|
||||
$this->aInherits[$sKey]['position']--;
|
||||
return $this->aInherits[$sKey]['items'][$this->aInherits[$sKey]['position']]['inherit'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает делегат модуля, экшена, сущности.
|
||||
* Если делегат не определен, отдает переданный в качестве sender`a параметр
|
||||
|
|
Loading…
Reference in a new issue