mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-05 07:54:24 +03:00
Доступ к приватным методам и свойствам экшена для обработчиков евентов
This commit is contained in:
parent
75354a0ce9
commit
67f11ae109
|
@ -117,6 +117,16 @@ abstract class Action extends LsObject {
|
||||||
unset($aArgs[0]);
|
unset($aArgs[0]);
|
||||||
return call_user_func_array(array($this,$sCall),$aArgs);
|
return call_user_func_array(array($this,$sCall),$aArgs);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Проверяет метод экшена на существование
|
||||||
|
*
|
||||||
|
* @param $sCall
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function ActionCallExists($sCall) {
|
||||||
|
return method_exists($this,$sCall);
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Добавляет евент в экшен
|
* Добавляет евент в экшен
|
||||||
* По сути является оберткой для AddEventPreg(), оставлен для простоты и совместимости с прошлыми версиями ядра
|
* По сути является оберткой для AddEventPreg(), оставлен для простоты и совместимости с прошлыми версиями ядра
|
||||||
|
|
|
@ -32,24 +32,14 @@ abstract class Event extends LsObject {
|
||||||
*/
|
*/
|
||||||
protected $oAction=null;
|
protected $oAction=null;
|
||||||
/**
|
/**
|
||||||
* Список приватных методов экшена для проксирования из внешнего евента
|
* Объект для анализа структуры класса экшена
|
||||||
*
|
*
|
||||||
* @var array
|
* @var null
|
||||||
*/
|
*/
|
||||||
protected $aMethodProxyAction=array(
|
protected $oActionReflection=null;
|
||||||
'GetDefaultEvent','GetEventMatch','GetParamEventMatch','GetParam','GetParams',
|
|
||||||
'SetParam','SetTemplate','SetTemplateAction','EventNotFound',
|
|
||||||
);
|
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
/**
|
|
||||||
* Переводим доступные методы к нижнему регистру
|
|
||||||
*/
|
|
||||||
$aMethods=array();
|
|
||||||
foreach($this->aMethodProxyAction as $sMethod) {
|
|
||||||
$aMethods[]=strtolower($sMethod);
|
|
||||||
}
|
|
||||||
$this->aMethodProxyAction=$aMethods;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -59,6 +49,7 @@ abstract class Event extends LsObject {
|
||||||
*/
|
*/
|
||||||
public function SetActionObject($oAction) {
|
public function SetActionObject($oAction) {
|
||||||
$this->oAction=$oAction;
|
$this->oAction=$oAction;
|
||||||
|
$this->oActionReflection=new ReflectionClass($this->oAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,31 +67,30 @@ abstract class Event extends LsObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __get($sName) {
|
public function __get($sName) {
|
||||||
if (property_exists($this->oAction,$sName)) {
|
if ($this->oActionReflection->hasProperty($sName)) {
|
||||||
return $this->oAction->$sName;
|
$oProperty = $this->oActionReflection->getProperty($sName);
|
||||||
|
$oProperty->setAccessible(true);
|
||||||
|
return $oProperty->getValue($this->oAction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __set($sName,$mValue) {
|
public function __set($sName,$mValue) {
|
||||||
if (property_exists($this->oAction,$sName)) {
|
if ($this->oActionReflection->hasProperty($sName)) {
|
||||||
return $this->oAction->$sName=$mValue;
|
$oProperty = $this->oActionReflection->getProperty($sName);
|
||||||
|
$oProperty->setAccessible(true);
|
||||||
|
$oProperty->setValue($this->oAction,$mValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __call($sName,$aArgs) {
|
public function __call($sName,$aArgs) {
|
||||||
/**
|
/**
|
||||||
* Обработка вызова приватных методов экшена
|
* Обработка вызова методов экшена
|
||||||
*/
|
*/
|
||||||
if (in_array(strtolower($sName),$this->aMethodProxyAction)) {
|
if ($this->oAction->ActionCallExists($sName)) {
|
||||||
array_unshift($aArgs,$sName);
|
array_unshift($aArgs,$sName);
|
||||||
return call_user_func_array(array($this->oAction,'ActionCall'),$aArgs);
|
return call_user_func_array(array($this->oAction,'ActionCall'),$aArgs);
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Обработка вызова публичных методов экшена
|
|
||||||
*/
|
|
||||||
if (method_exists($this->oAction,$sName)) {
|
|
||||||
return call_user_func_array(array($this->oAction,$sName),$aArgs);
|
|
||||||
}
|
|
||||||
return Engine::getInstance()->_CallModule($sName,$aArgs);
|
return Engine::getInstance()->_CallModule($sName,$aArgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue