mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-09 01:44:25 +03:00
Actions inheritance refactoring. Now it's possible to inherit actions of other plugins, all templates will be inherited automatically.
This commit is contained in:
parent
4047d7233d
commit
c32e37889f
|
@ -215,47 +215,43 @@ abstract class Action extends Object {
|
||||||
* @param string $sTemplate Путь до шаблона относительно каталога шаблонов экшена
|
* @param string $sTemplate Путь до шаблона относительно каталога шаблонов экшена
|
||||||
*/
|
*/
|
||||||
protected function SetTemplateAction($sTemplate) {
|
protected function SetTemplateAction($sTemplate) {
|
||||||
$sActionClass=$this->GetActionClass();
|
$sAction = $this->GetActionClass();
|
||||||
/**
|
$sActionDelegater = $this->Plugin_GetDelegater('action',$this->GetActionClass());
|
||||||
* Если класс не является делегатом плагина, устанавлваем шаблон по умолчанию.
|
while(empty($sRootDelegater)) {
|
||||||
* В случае делегирования, проверяем сначала имеет ли указанный плагин замену для шаблона.
|
if($sAction==$sActionDelegater) {
|
||||||
*/
|
$sRootDelegater = $sAction;
|
||||||
if(!$this->Plugin_isDelegated('action',$sActionClass)) {
|
}
|
||||||
$this->sActionTemplate='actions/'.$sActionClass.'/'.$sTemplate.'.tpl';
|
$sAction = $sActionDelegater;
|
||||||
} else {
|
$sActionDelegater = $this->Plugin_GetDelegater('action',$sActionDelegater);
|
||||||
$sDelegater = $this->Plugin_GetDelegater('action',$sActionClass);
|
|
||||||
$sTemplatePath = Plugin::GetTemplatePath($this->Plugin_GetDelegateSign('action',$sDelegater));
|
|
||||||
|
|
||||||
$this->sActionTemplate = is_file($sFile=$sTemplatePath.'actions/'.$sDelegater.'/'.$sTemplate.'.tpl')
|
|
||||||
? $sFile
|
|
||||||
: 'actions/'.$sDelegater.'/'.$sTemplate.'.tpl';
|
|
||||||
}
|
}
|
||||||
|
$aDelegates = $this->Plugin_collectAllDelegatesRecursive(array($sRootDelegater),'action');
|
||||||
|
$sActionTemplatePath = $sTemplate.'.tpl';
|
||||||
|
foreach($aDelegates as $sAction) {
|
||||||
|
if(preg_match('/^(Plugin([\w]+)_)?Action([\w]+)$/i',$sAction,$aMatches)) {
|
||||||
|
$sTemplatePath = $this->Plugin_GetDelegate('template','actions/Action'.ucfirst($aMatches[3]).'/'.$sTemplate.'.tpl');
|
||||||
|
if(empty($aMatches[1])) {
|
||||||
|
$sActionTemplatePath = $sTemplatePath;
|
||||||
|
} else {
|
||||||
|
$sTemplatePath = Plugin::GetTemplatePath($sAction).$sTemplatePath;
|
||||||
|
if(is_file($sTemplatePath)) {
|
||||||
|
$sActionTemplatePath = $sTemplatePath;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->sActionTemplate = $sActionTemplatePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Получить шаблон
|
* Получить шаблон
|
||||||
* Если шаблон не определен то возвращаем дефолтный шаблон евента: action/{Action}.{event}.tpl
|
* Если шаблон не определен то возвращаем дефолтный шаблон евента: action/{Action}.{event}.tpl
|
||||||
* Внимание! По умолчанию, шаблон будет получен без учета делегирования экшена.
|
|
||||||
*
|
*
|
||||||
* @return unknown
|
* @return unknown
|
||||||
*/
|
*/
|
||||||
public function GetTemplate() {
|
public function GetTemplate() {
|
||||||
if (is_null($this->sActionTemplate)) {
|
if (is_null($this->sActionTemplate)) {
|
||||||
$sActionClass=$this->GetActionClass();
|
$this->SetTemplateAction($this->sCurrentEvent);
|
||||||
/**
|
|
||||||
* Если класс не является делегатом плагина, устанавлваем шаблон по умолчанию.
|
|
||||||
* В случае делегирования, проверяем сначала имеет ли указанный плагин замену для шаблона.
|
|
||||||
*/
|
|
||||||
if(!$this->Plugin_isDelegated('action',$sActionClass)) {
|
|
||||||
$this->sActionTemplate='actions/'.$sActionClass.'/'.$this->sCurrentEvent.'.tpl';
|
|
||||||
} else {
|
|
||||||
$sDelegater = $this->Plugin_GetDelegater('action',$sActionClass);
|
|
||||||
$sTemplatePath = Plugin::GetTemplatePath($this->Plugin_GetDelegateSign('action',$sDelegater));
|
|
||||||
|
|
||||||
$this->sActionTemplate = is_file($sFile=$sTemplatePath.'actions/'.$sDelegater.'/'.$this->sCurrentEvent.'.tpl')
|
|
||||||
? $sFile
|
|
||||||
: 'actions/'.$sDelegater.'/'.$this->sCurrentEvent.'.tpl';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return $this->sActionTemplate;
|
return $this->sActionTemplate;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,33 +84,5 @@ abstract class ActionPlugin extends Action {
|
||||||
$this->sTemplatePathPlugin = $sTemplatePath;
|
$this->sTemplatePathPlugin = $sTemplatePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Устанавливает какой шаблон выводить
|
|
||||||
*
|
|
||||||
* @param string $sTemplate Путь до шаблона относительно каталога шаблонов экшена
|
|
||||||
*/
|
|
||||||
protected function SetTemplateAction($sTemplate) {
|
|
||||||
if($sActionTemplate=preg_match('/^Plugin([\w]+)_Action([\w]+)$/i',$this->GetActionClass(),$aMatches)) {
|
|
||||||
$sTemplatePath = 'actions/Action'.ucfirst($aMatches[2]).'/'.$sTemplate.'.tpl';
|
|
||||||
$sActionTemplate = is_file($sPluginTemplatePath=$this->getTemplatePathPlugin().$sTemplatePath)
|
|
||||||
? $sPluginTemplatePath
|
|
||||||
: $sTemplatePath;
|
|
||||||
}
|
|
||||||
$this->sActionTemplate = $sActionTemplate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Получить шаблон
|
|
||||||
* Если шаблон не определен то возвращаем дефолтный шаблон евента: action/{Action}.{event}.tpl
|
|
||||||
*
|
|
||||||
* @return unknown
|
|
||||||
*/
|
|
||||||
public function GetTemplate() {
|
|
||||||
if (is_null($this->sActionTemplate)) {
|
|
||||||
$this->SetTemplateAction($this->sCurrentEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->sActionTemplate;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
|
@ -397,6 +397,13 @@ class ModulePlugin extends Module {
|
||||||
return $this->aInherits[$sFrom]['items'][$this->aInherits[$sFrom]['position']]['inherit'];
|
return $this->aInherits[$sFrom]['items'][$this->aInherits[$sFrom]['position']]['inherit'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetInherits($sFrom) {
|
||||||
|
if (isset($this->aInherits[trim($sFrom)])) {
|
||||||
|
return $this->aInherits[trim($sFrom)]['items'];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public function GetLastInherit($sFrom) {
|
public function GetLastInherit($sFrom) {
|
||||||
if (isset($this->aInherits[trim($sFrom)])) {
|
if (isset($this->aInherits[trim($sFrom)])) {
|
||||||
return $this->aInherits[trim($sFrom)]['items'][count($this->aInherits[trim($sFrom)]['items'])-1];
|
return $this->aInherits[trim($sFrom)]['items'][count($this->aInherits[trim($sFrom)]['items'])-1];
|
||||||
|
@ -420,6 +427,24 @@ class ModulePlugin extends Module {
|
||||||
return $sFrom;
|
return $sFrom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function GetDelegates($sType,$sFrom) {
|
||||||
|
if (isset($this->aDelegates[$sType][$sFrom]['delegate'])) {
|
||||||
|
return array($this->aDelegates[$sType][$sFrom]['delegate']);
|
||||||
|
} else if($aInherits=$this->GetInherits($sFrom)) {
|
||||||
|
return array_map(create_function('$aInherit','return $aInherit["inherit"];'),array_reverse($aInherits));
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function collectAllDelegatesRecursive($aDelegates,$sType) {
|
||||||
|
foreach($aDelegates as $sClass) {
|
||||||
|
if($aNewDelegates=$this->GetDelegates($sType,$sClass)) {
|
||||||
|
$aDelegates = array_merge($this->collectAllDelegatesRecursive($aNewDelegates,$sType),$aDelegates);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $aDelegates;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Возвращает делегирующий объект по имени делегата
|
* Возвращает делегирующий объект по имени делегата
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue