mirror of
https://github.com/Oreolek/ifhub.club.git
synced 2024-07-01 14:05:07 +03:00
Refactoring engine by 1d1ot
This commit is contained in:
parent
f906cedc89
commit
e5fd1d74bb
|
@ -28,12 +28,99 @@ require_once("Router.class.php");
|
|||
require_once("Entity.class.php");
|
||||
require_once("Mapper.class.php");
|
||||
|
||||
|
||||
/**
|
||||
* Основной класс движка, который позволяет напрямую обращаться к любому модулю
|
||||
*
|
||||
*/
|
||||
class Engine extends Object {
|
||||
|
||||
/**
|
||||
* Имя плагина
|
||||
* @var int
|
||||
*/
|
||||
const CI_PLUGIN = 1;
|
||||
|
||||
/**
|
||||
* Имя экшна
|
||||
* @var int
|
||||
*/
|
||||
const CI_ACTION = 2;
|
||||
|
||||
/**
|
||||
* Имя модуля
|
||||
* @var int
|
||||
*/
|
||||
const CI_MODULE = 4;
|
||||
|
||||
/**
|
||||
* Имя сущности
|
||||
* @var int
|
||||
*/
|
||||
const CI_ENTITY = 8;
|
||||
|
||||
/**
|
||||
* Имя маппера
|
||||
* @var int
|
||||
*/
|
||||
const CI_MAPPER = 16;
|
||||
|
||||
/**
|
||||
* Имя метода
|
||||
* @var int
|
||||
*/
|
||||
const CI_METHOD = 32;
|
||||
|
||||
/**
|
||||
* Имя хука
|
||||
* @var int
|
||||
*/
|
||||
const CI_HOOK = 64;
|
||||
|
||||
/**
|
||||
* Имя класс наследования
|
||||
* @var int
|
||||
*/
|
||||
const CI_INHERIT = 128;
|
||||
|
||||
/**
|
||||
* Префикс плагина
|
||||
* @var int
|
||||
*/
|
||||
const CI_PPREFIX = 8192;
|
||||
|
||||
/**
|
||||
* Разобранный класс наследования
|
||||
* @var int
|
||||
*/
|
||||
const CI_INHERITS = 16384;
|
||||
|
||||
/**
|
||||
* Путь к файлу класса
|
||||
* @var int
|
||||
*/
|
||||
const CI_CLASSPATH = 32768;
|
||||
|
||||
/**
|
||||
* Все свойства класса
|
||||
* @var int
|
||||
*/
|
||||
const CI_ALL = 65535;
|
||||
|
||||
/**
|
||||
* Свойства по-умолчанию
|
||||
* CI_ALL ^ (CI_CLASSPATH | CI_INHERITS | CI_PPREFIX)
|
||||
* @var int
|
||||
*/
|
||||
const CI_DEFAULT = 8191;
|
||||
|
||||
/**
|
||||
* Объекты
|
||||
* CI_ACTION | CI_MAPPER | CI_HOOK | CI_PLUGIN | CI_ACTION | CI_MODULE | CI_ENTITY
|
||||
* @var int
|
||||
*/
|
||||
const CI_OBJECT = 95;
|
||||
|
||||
static protected $oInstance=null;
|
||||
|
||||
protected $aModules=array();
|
||||
|
@ -120,7 +207,7 @@ class Engine extends Object {
|
|||
*/
|
||||
$oProfiler=ProfilerSimple::getInstance();
|
||||
$iTimeId=$oProfiler->Start('InitModule',get_class($oModule));
|
||||
|
||||
|
||||
$this->InitModule($oModule);
|
||||
|
||||
$oProfiler->Stop($iTimeId);
|
||||
|
@ -130,40 +217,41 @@ class Engine extends Object {
|
|||
|
||||
/**
|
||||
* Инициализирует модуль
|
||||
*
|
||||
*
|
||||
* @param unknown_type $oModule
|
||||
* @param unknown_type $bHookParent
|
||||
*/
|
||||
protected function InitModule($oModule){
|
||||
$sOrigClassName = $sClassName = get_class($oModule);
|
||||
protected function InitModule($oModule, $bHookParent = true){
|
||||
$sOrigClassName = $sClassName = get_class($oModule);
|
||||
$bRunHooks = false;
|
||||
|
||||
|
||||
if($this->isInitModule('ModuleHook')){
|
||||
$bRunHooks = true;
|
||||
while(preg_match('#^Plugin#i', $sClassName)){
|
||||
$sParentClassName = get_parent_class($sClassName);
|
||||
if($sParentClassName == 'Module'){
|
||||
break;
|
||||
if($bHookParent){
|
||||
while(self::GetPluginName($sClassName)){
|
||||
$sParentClassName = get_parent_class($sClassName);
|
||||
if(!self::GetClassInfo($sParentClassName, self::CI_MODULE, true)){
|
||||
break;
|
||||
}
|
||||
$sClassName = $sParentClassName;
|
||||
}
|
||||
$sClassName = $sParentClassName;
|
||||
}
|
||||
}
|
||||
|
||||
if($bRunHooks || $sClassName == 'ModuleHook'){
|
||||
$sHookPrefix = 'module_';
|
||||
if($sPluginName = self::GetPluginName($sClassName)) {
|
||||
if($sPluginName = self::GetPluginName($sClassName)){
|
||||
$sHookPrefix .= "plugin{$sPluginName}_";
|
||||
}
|
||||
$sHookPrefix .= self::GetModuleName($sClassName).'_init_';
|
||||
}
|
||||
|
||||
if($bRunHooks){
|
||||
$this->Hook_Run($sHookPrefix.'before');
|
||||
}
|
||||
$oModule->Init();
|
||||
$oModule->SetInit();
|
||||
$oModule->SetInit();
|
||||
if($bRunHooks || $sClassName == 'ModuleHook'){
|
||||
$this->Hook_Run($sHookPrefix.'after');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -199,6 +287,7 @@ class Engine extends Object {
|
|||
$oProfiler->Stop($iTimeId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Выполняет загрузку модуля по его названию
|
||||
*
|
||||
|
@ -255,8 +344,8 @@ class Engine extends Object {
|
|||
|
||||
if($aFiles and count($aFiles)) {
|
||||
foreach ($aFiles as $sFile) {
|
||||
if (preg_match("/Hook([\w]+)\.class\.php$/i",basename($sFile),$aMatch)) {
|
||||
require_once($sFile);
|
||||
if (preg_match("/Hook([^_]+)\.class\.php$/i",basename($sFile),$aMatch)) {
|
||||
//require_once($sFile);
|
||||
$sClassName='Hook'.$aMatch[1];
|
||||
$oHook=new $sClassName;
|
||||
$oHook->RegisterHook();
|
||||
|
@ -275,8 +364,7 @@ class Engine extends Object {
|
|||
*
|
||||
*/
|
||||
protected function InitPluginHooks() {
|
||||
if($aPluginList = @file(Config::Get('path.root.server').'/plugins/plugins.dat')) {
|
||||
$aPluginList=array_map('trim',$aPluginList);
|
||||
if($aPluginList = func_list_plugins()) {
|
||||
|
||||
$aFiles=array();
|
||||
$sDirHooks=Config::Get('path.root.server').'/plugins/';
|
||||
|
@ -285,8 +373,8 @@ class Engine extends Object {
|
|||
$aFiles=glob($sDirHooks.$sPluginName.'/classes/hooks/Hook*.class.php');
|
||||
if($aFiles and count($aFiles)) {
|
||||
foreach ($aFiles as $sFile) {
|
||||
if (preg_match("/Hook([\w]+)\.class\.php$/i",basename($sFile),$aMatch)) {
|
||||
require_once($sFile);
|
||||
if (preg_match("/Hook([^_]+)\.class\.php$/i",basename($sFile),$aMatch)) {
|
||||
//require_once($sFile);
|
||||
$sPluginName = ucfirst($sPluginName);
|
||||
$sClassName="Plugin{$sPluginName}_Hook{$aMatch[1]}";
|
||||
$oHook=new $sClassName;
|
||||
|
@ -303,20 +391,12 @@ class Engine extends Object {
|
|||
*
|
||||
*/
|
||||
protected function LoadPlugins() {
|
||||
if($aPluginList = @file(Config::Get('path.root.server').'/plugins/plugins.dat')) {
|
||||
$aPluginList=array_map('trim',$aPluginList);
|
||||
|
||||
if($aPluginList = func_list_plugins()) {
|
||||
foreach ($aPluginList as $sPluginName) {
|
||||
$sDirPlugins=Config::Get('path.root.server').'/plugins/';
|
||||
$sPluginNameClass='Plugin'.ucfirst($sPluginName);
|
||||
$sFile="{$sDirPlugins}{$sPluginName}/{$sPluginNameClass}.class.php";
|
||||
if(is_file($sFile)) {
|
||||
require_once($sFile);
|
||||
$sClassName="{$sPluginNameClass}";
|
||||
$oPlugin=new $sClassName;
|
||||
$oPlugin->Delegate();
|
||||
$this->aPlugins[$sPluginName]=$oPlugin;
|
||||
}
|
||||
$sClassName='Plugin'.ucfirst($sPluginName);
|
||||
$oPlugin=new $sClassName;
|
||||
$oPlugin->Delegate();
|
||||
$this->aPlugins[$sPluginName]=$oPlugin;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -346,19 +426,22 @@ class Engine extends Object {
|
|||
* @param string $sFile
|
||||
* @return mixed
|
||||
*/
|
||||
public function isFileExists($sFile,$iTime=3600) { return file_exists($sFile);
|
||||
if (strpos($sFile,'/Cache.class.')!==false) {
|
||||
return file_exists($sFile);
|
||||
public function isFileExists($sFile,$iTime=3600) {
|
||||
// пока так
|
||||
return file_exists($sFile);
|
||||
|
||||
if(
|
||||
!$this->isInit('cache')
|
||||
|| !Config::Get('sys.cache.use')
|
||||
|| Config::Get('sys.cache.type') != 'memory'
|
||||
){
|
||||
return file_exists($sFile);
|
||||
}
|
||||
if (SYS_CACHE_USE and SYS_CACHE_TYPE==SYS_CACHE_TYPE_MEMORY) {
|
||||
if (false === ($data = $this->Cache_Get("file_exists_{$sFile}"))) {
|
||||
$data=file_exists($sFile);
|
||||
$this->Cache_Set((int)$data, "file_exists_{$sFile}", array(), $iTime);
|
||||
}
|
||||
return $data;
|
||||
} else {
|
||||
return file_exists($sFile);
|
||||
if (false === ($data = $this->Cache_Get("file_exists_{$sFile}"))) {
|
||||
$data=file_exists($sFile);
|
||||
$this->Cache_Set((int)$data, "file_exists_{$sFile}", array(), $iTime);
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
/**
|
||||
* Вызывает метод нужного модуля
|
||||
|
@ -368,13 +451,6 @@ class Engine extends Object {
|
|||
* @return unknown
|
||||
*/
|
||||
public function _CallModule($sName,$aArgs) {
|
||||
$sArgs='';
|
||||
$aStrArgs=array();
|
||||
foreach ($aArgs as $sKey => $arg) {
|
||||
$aStrArgs[]='$aArgs['.$sKey.']';
|
||||
}
|
||||
$sArgs=join(',',$aStrArgs);
|
||||
|
||||
list($oModule,$sModuleName,$sMethod)=$this->GetModule($sName);
|
||||
|
||||
if (!method_exists($oModule,$sMethod)) {
|
||||
|
@ -419,27 +495,38 @@ class Engine extends Object {
|
|||
/**
|
||||
* Поддержка полного синтаксиса при вызове метода модуля
|
||||
*/
|
||||
if (preg_match("/^Plugin(\w+)\_Module(\w+)\_(\w+)$/i",$sName,$aMatch)) {
|
||||
$sName="Plugin{$aMatch[1]}_{$aMatch[2]}_{$aMatch[3]}";
|
||||
}
|
||||
if (preg_match("/^Module(\w+)\_(\w+)$/i",$sName,$aMatch)) {
|
||||
$sName="{$aMatch[1]}_{$aMatch[2]}";
|
||||
$aInfo = self::GetClassInfo(
|
||||
$sName,
|
||||
self::CI_MODULE
|
||||
|self::CI_PPREFIX
|
||||
|self::CI_METHOD
|
||||
);
|
||||
if($aInfo[self::CI_MODULE] && $aInfo[self::CI_METHOD]){
|
||||
$sName = $aInfo[self::CI_MODULE].'_'.$aInfo[self::CI_METHOD];
|
||||
if($aInfo[self::CI_PPREFIX]){
|
||||
$sName = $aInfo[self::CI_PPREFIX].$sName;
|
||||
}
|
||||
}
|
||||
|
||||
$aName=explode("_",$sName);
|
||||
|
||||
if(count($aName)==2) {
|
||||
$sModuleName=$aName[0];
|
||||
$sModuleClass='Module'.$aName[0];
|
||||
$sMethod=$aName[1];
|
||||
} else {
|
||||
} elseif (count($aName)==3) {
|
||||
$sModuleName=$aName[0].'_'.$aName[1];
|
||||
$sModuleClass=$aName[0].'_Module'.$aName[1];
|
||||
$sMethod=$aName[2];
|
||||
} else {
|
||||
throw new Exception("Undefined method module: ".$sName);
|
||||
}
|
||||
/**
|
||||
* Подхватыем делегат модуля (в случае наличия такового)
|
||||
*/
|
||||
if(!in_array($sModuleName,array('Plugin','Hook'))) $sModuleClass=$this->Plugin_GetDelegate('module',$sModuleClass);
|
||||
if(!in_array($sModuleName,array('Plugin','Hook'))){
|
||||
$sModuleClass=$this->Plugin_GetDelegate('module',$sModuleClass);
|
||||
}
|
||||
|
||||
if (isset($this->aModules[$sModuleClass])) {
|
||||
$oModule=$this->aModules[$sModuleClass];
|
||||
|
@ -470,7 +557,7 @@ class Engine extends Object {
|
|||
}
|
||||
|
||||
/**
|
||||
* Блокируем копирование/клонирование объекта роутинга
|
||||
* Блокируем копирование/клонирование объекта ядра
|
||||
*
|
||||
*/
|
||||
protected function __clone() {
|
||||
|
@ -485,9 +572,14 @@ class Engine extends Object {
|
|||
* @return mixed
|
||||
*/
|
||||
public static function GetMapper($sClassName,$sName=null,$oConnect=null) {
|
||||
if (preg_match("/^(?:Plugin\w+_)?Module(\w+)$/i",$sClassName,$aMatch)) {
|
||||
$sModuleName = self::GetClassInfo(
|
||||
$sClassName,
|
||||
self::CI_MODULE,
|
||||
true
|
||||
);
|
||||
if ($sModuleName) {
|
||||
if (!$sName) {
|
||||
$sName=$aMatch[1];
|
||||
$sName=$sModuleName;
|
||||
}
|
||||
$sClass=$sClassName.'_Mapper'.$sName;
|
||||
if (!$oConnect) {
|
||||
|
@ -516,12 +608,19 @@ class Engine extends Object {
|
|||
$sEntity = $sModule = $sName;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
case 1:
|
||||
/**
|
||||
* Поддержка полного синтаксиса при вызове сущности
|
||||
*/
|
||||
if (preg_match("/^Module(\w+)\_Entity(\w+)$/i",$sName,$aMatch)) {
|
||||
$sName="{$aMatch[1]}_{$aMatch[2]}";
|
||||
$aInfo = self::GetClassInfo(
|
||||
$sName,
|
||||
self::CI_ENTITY
|
||||
|self::CI_MODULE
|
||||
|self::CI_PLUGIN
|
||||
);
|
||||
if ($aInfo[self::CI_MODULE]
|
||||
&& $aInfo[self::CI_ENTITY]) {
|
||||
$sName=$aInfo[self::CI_MODULE].'_'.$aInfo[self::CI_ENTITY];
|
||||
}
|
||||
|
||||
list($sModule,$sEntity) = explode('_',$sName,2);
|
||||
|
@ -529,8 +628,8 @@ class Engine extends Object {
|
|||
* Обслуживание короткой записи сущностей плагинов
|
||||
* PluginTest_Test -> PluginTest_ModuleTest_EntityTest
|
||||
*/
|
||||
if(substr($sModule,0,6)=='Plugin' and strlen($sModule)>6) {
|
||||
$sPlugin = substr($sModule,6);
|
||||
if($aInfo[self::CI_PLUGIN]) {
|
||||
$sPlugin = $aInfo[self::CI_PLUGIN];
|
||||
$sModule = $sEntity;
|
||||
}
|
||||
break;
|
||||
|
@ -539,15 +638,26 @@ class Engine extends Object {
|
|||
/**
|
||||
* Поддержка полного синтаксиса при вызове сущности плагина
|
||||
*/
|
||||
if (preg_match("/^Plugin(\w+)\_Module(\w+)\_Entity(\w+)$/i",$sName,$aMatch)) {
|
||||
$sName="Plugin{$aMatch[1]}_{$aMatch[2]}_{$aMatch[3]}";
|
||||
$aInfo = self::GetClassInfo(
|
||||
$sName,
|
||||
self::CI_ENTITY
|
||||
|self::CI_MODULE
|
||||
|self::CI_PLUGIN
|
||||
);
|
||||
if ($aInfo[self::CI_PLUGIN]
|
||||
&& $aInfo[self::CI_MODULE]
|
||||
&& $aInfo[self::CI_ENTITY]) {
|
||||
$sName='Plugin'.$aInfo[self::CI_PLUGIN]
|
||||
.'_'.$aInfo[self::CI_MODULE]
|
||||
.'_'.$aInfo[self::CI_ENTITY]
|
||||
;
|
||||
}
|
||||
/**
|
||||
* Entity плагина
|
||||
*/
|
||||
if(substr($sName,0,6)=='Plugin') {
|
||||
list($sPlugin,$sModule,$sEntity)=explode('_',$sName);
|
||||
$sPlugin = substr($sPlugin,6);
|
||||
if($aInfo[self::CI_PLUGIN]) {
|
||||
list(,$sModule,$sEntity)=explode('_',$sName);
|
||||
$sPlugin = $aInfo[self::CI_PLUGIN];
|
||||
} else {
|
||||
throw new Exception("Unknown entity '{$sName}' given.");
|
||||
}
|
||||
|
@ -571,152 +681,227 @@ class Engine extends Object {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public static function GetPluginName($oModule) {
|
||||
if (preg_match('/Plugin([^_]+)/',is_string($oModule) ? $oModule : get_class($oModule),$aMatches)) {
|
||||
if(isset($aMatches[1])) {
|
||||
return $aMatches[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
public static function GetPluginName($oModule) {
|
||||
return self::GetClassInfo($oModule, self::CI_PLUGIN, true);
|
||||
}
|
||||
|
||||
public static function GetPluginPrefix($oModule) {
|
||||
if($sPluginName = self::GetPluginName($oModule)) {
|
||||
return 'Plugin'.$sPluginName.'_';
|
||||
}
|
||||
return '';
|
||||
return self::GetClassInfo($oModule, self::CI_PPREFIX, true);
|
||||
}
|
||||
|
||||
public static function GetModuleName($oModule) {
|
||||
if (preg_match('/Module([^_]+)/',is_string($oModule) ? $oModule : get_class($oModule),$aMatches)) {
|
||||
if(isset($aMatches[1])) {
|
||||
return $aMatches[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return self::GetClassInfo($oModule, self::CI_MODULE, true);
|
||||
}
|
||||
|
||||
public static function GetEntityName($oEntity) {
|
||||
if (preg_match('/Entity([^_]+)/',is_string($oEntity) ? $oEntity : get_class($oEntity),$aMatches)) {
|
||||
if(isset($aMatches[1])) {
|
||||
return $aMatches[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return self::GetClassInfo($oEntity, self::CI_ENTITY, true);
|
||||
}
|
||||
|
||||
public static function GetActionName($oAction) {
|
||||
return self::GetClassInfo($oAction, self::CI_ACTION, true);
|
||||
}
|
||||
|
||||
public static function GetClassInfo($oObject,$iFlag=self::CI_DEFAULT,$bSingle=false){
|
||||
$sClassName = is_string($oObject) ? $oObject : get_class($oObject);
|
||||
$aResult = array();
|
||||
if($iFlag & self::CI_PLUGIN){
|
||||
$aResult[self::CI_PLUGIN] = preg_match('/^Plugin([^_]+)/',$sClassName,$aMatches)
|
||||
? $aMatches[1]
|
||||
: null
|
||||
;
|
||||
}
|
||||
if($iFlag & self::CI_ACTION){
|
||||
$aResult[self::CI_ACTION] = preg_match('/^(?:Plugin[^_]+_|)Action([^_]+)/',$sClassName,$aMatches)
|
||||
? $aMatches[1]
|
||||
: null
|
||||
;
|
||||
}
|
||||
if($iFlag & self::CI_MODULE){
|
||||
$aResult[self::CI_MODULE] = preg_match('/^(?:Plugin[^_]+_|)Module(?:ORM|)([^_]+)/',$sClassName,$aMatches)
|
||||
? $aMatches[1]
|
||||
: null
|
||||
;
|
||||
}
|
||||
if($iFlag & self::CI_ENTITY){
|
||||
$aResult[self::CI_ENTITY] = preg_match('/_Entity(?:ORM|)([^_]+)/',$sClassName,$aMatches)
|
||||
? $aMatches[1]
|
||||
: null
|
||||
;
|
||||
}
|
||||
if($iFlag & self::CI_MAPPER){
|
||||
$aResult[self::CI_MAPPER] = preg_match('/_Mapper(?:ORM|)([^_]+)/',$sClassName,$aMatches)
|
||||
? $aMatches[1]
|
||||
: null
|
||||
;
|
||||
}
|
||||
if($iFlag & self::CI_HOOK){
|
||||
$aResult[self::CI_HOOK] = preg_match('/^(?:Plugin[^_]+_|)Hook([^_]+)$/',$sClassName,$aMatches)
|
||||
? $aMatches[1]
|
||||
: null
|
||||
;
|
||||
}
|
||||
if($iFlag & self::CI_METHOD){
|
||||
$sModuleName = isset($aResult[self::CI_MODULE])
|
||||
? $aResult[self::CI_MODULE]
|
||||
: self::GetClassInfo($sClassName, self::CI_MODULE, true)
|
||||
;
|
||||
$aResult[self::CI_METHOD] = preg_match('/_([^_]+)$/',$sClassName,$aMatches)
|
||||
? ($sModuleName && strtolower($aMatches[1]) == strtolower('module'.$sModuleName)
|
||||
? null
|
||||
: $aMatches[1]
|
||||
)
|
||||
: null
|
||||
;
|
||||
}
|
||||
if($iFlag & self::CI_PPREFIX){
|
||||
$sPluginName = isset($aResult[self::CI_PLUGIN])
|
||||
? $aResult[self::CI_PLUGIN]
|
||||
: self::GetClassInfo($sClassName, self::CI_PLUGIN, true)
|
||||
;
|
||||
$aResult[self::CI_PPREFIX] = $sPluginName
|
||||
? "Plugin{$sPluginName}_"
|
||||
: ''
|
||||
;
|
||||
}
|
||||
if($iFlag & self::CI_INHERIT){
|
||||
$aResult[self::CI_INHERIT] = preg_match('/_Inherits?_(\w+)$/',$sClassName,$aMatches)
|
||||
? $aMatches[1]
|
||||
: null
|
||||
;
|
||||
}
|
||||
if($iFlag & self::CI_INHERITS){
|
||||
$sInherit = isset($aResult[self::CI_INHERIT])
|
||||
? $aResult[self::CI_INHERIT]
|
||||
: self::GetClassInfo($sClassName, self::CI_INHERIT, true)
|
||||
;
|
||||
$aResult[self::CI_INHERITS] = $sInherit
|
||||
? self::GetClassInfo(
|
||||
$sClassName,
|
||||
self::CI_OBJECT,
|
||||
false)
|
||||
: null
|
||||
;
|
||||
}
|
||||
if($iFlag & self::CI_CLASSPATH){
|
||||
$aResult[self::CI_CLASSPATH] = self::GetClassPath($sClassName);
|
||||
}
|
||||
|
||||
return $bSingle ? array_pop($aResult) : $aResult;
|
||||
}
|
||||
|
||||
|
||||
public static function GetClassPath($oObject){
|
||||
$aInfo = self::GetClassInfo(
|
||||
$oObject,
|
||||
self::CI_OBJECT
|
||||
);
|
||||
$sPath = Config::get('path.root.server').'/';
|
||||
if($aInfo[self::CI_ENTITY]){
|
||||
// Сущность
|
||||
if($aInfo[self::CI_PLUGIN]){
|
||||
// Сущность модуля плагина
|
||||
$sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN])
|
||||
.'/classes/modules/'.strtolower($aInfo[self::CI_MODULE])
|
||||
.'/entity/'.$aInfo[self::CI_ENTITY].'.entity.class.php'
|
||||
;
|
||||
}else{
|
||||
// Сущность модуля ядра
|
||||
$sPath .= 'classes/modules/'.strtolower($aInfo[self::CI_MODULE])
|
||||
.'/entity/'.$aInfo[self::CI_ENTITY].'.entity.class.php'
|
||||
;
|
||||
}
|
||||
}elseif($aInfo[self::CI_MAPPER]){
|
||||
// Маппер
|
||||
if($aInfo[self::CI_PLUGIN]){
|
||||
// Маппер модуля плагина
|
||||
$sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN])
|
||||
.'/classes/modules/'.strtolower($aInfo[self::CI_MODULE])
|
||||
.'/mapper/'.$aInfo[self::CI_MAPPER].'.mapper.class.php'
|
||||
;
|
||||
}else{
|
||||
// Маппер модуля ядра
|
||||
$sPath .= 'classes/modules/'.strtolower($aInfo[self::CI_MODULE])
|
||||
.'/mapper/'.$aInfo[self::CI_MAPPER].'.mapper.class.php'
|
||||
;
|
||||
}
|
||||
}elseif($aInfo[self::CI_ACTION]){
|
||||
// Экшн
|
||||
if($aInfo[self::CI_PLUGIN]){
|
||||
// Экшн плагина
|
||||
$sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN])
|
||||
.'/classes/actions/Action'.$aInfo[self::CI_ACTION].'.class.php'
|
||||
;
|
||||
}else{
|
||||
// Экшн ядра
|
||||
$sPath .= 'classes/actions/Action'
|
||||
.$aInfo[self::CI_ACTION].'.class.php'
|
||||
;
|
||||
}
|
||||
}elseif($aInfo[self::CI_MODULE]){
|
||||
// Модуль
|
||||
if($aInfo[self::CI_PLUGIN]){
|
||||
// Модуль плагина
|
||||
$sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN])
|
||||
.'/classes/modules/'.strtolower($aInfo[self::CI_MODULE])
|
||||
.'/'.$aInfo[self::CI_MODULE].'.class.php';
|
||||
;
|
||||
}else{
|
||||
// Модуль ядра
|
||||
$sPath .= 'classes/modules/'.strtolower($aInfo[self::CI_MODULE])
|
||||
.'/'.$aInfo[self::CI_MODULE].'.class.php'
|
||||
;
|
||||
if(!is_file($sPath)){
|
||||
$sPath = str_replace('/classes/modules/','/engine/modules/',$sPath);
|
||||
}
|
||||
}
|
||||
}elseif($aInfo[self::CI_HOOK]){
|
||||
// Хук
|
||||
if($aInfo[self::CI_PLUGIN]){
|
||||
// Хук плагина
|
||||
$sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN])
|
||||
.'/classes/hooks/Hook'.$aInfo[self::CI_HOOK]
|
||||
.'.class.php';
|
||||
;
|
||||
}else{
|
||||
// Хук ядра
|
||||
$sPath .= 'classes/hooks/Hook'.$aInfo[self::CI_HOOK].'.class.php';
|
||||
}
|
||||
}elseif($aInfo[self::CI_PLUGIN]){
|
||||
// Плагин
|
||||
$sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN])
|
||||
.'/Plugin'.$aInfo[self::CI_PLUGIN]
|
||||
.'.class.php';
|
||||
;
|
||||
}else{
|
||||
$sClassName = is_string($oObject) ? $oObject : get_class($oObject);
|
||||
$sPath .= 'engine/classes/'.$sClassName.'.class.php';
|
||||
}
|
||||
return is_file($sPath) ? $sPath : null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Автозагрузка кслассов
|
||||
* Автозагрузка классов
|
||||
*
|
||||
* @param unknown_type $sClassName
|
||||
*/
|
||||
function __autoload($sClassName) {
|
||||
/**
|
||||
* Если класс подходит под шаблон класса сущности то загружаем его
|
||||
*/
|
||||
if (preg_match("/^Module(\w+)\_Entity(\w+)$/i",$sClassName,$aMatch)) {
|
||||
$tm1=microtime(true);
|
||||
|
||||
$sFileClass=Config::get('path.root.server').'/classes/modules/'.strtolower($aMatch[1]).'/entity/'.$aMatch[2].'.entity.class.php';
|
||||
|
||||
if (file_exists($sFileClass)) {
|
||||
require_once($sFileClass);
|
||||
$tm2=microtime(true);
|
||||
dump($sClassName." - \t\t".($tm2-$tm1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Если класс подходит под шаблон класса сущности плагина
|
||||
*/
|
||||
if (preg_match("/^Plugin(\w+)\_Module(\w+)\_Entity(\w+)$/i",$sClassName,$aMatch)) {
|
||||
$tm1=microtime(true);
|
||||
|
||||
$sFileClass= Config::get('path.root.server').'/plugins/'.strtolower($aMatch[1]).'/classes/modules/'.strtolower($aMatch[2]).'/entity/'.$aMatch[3].'.entity.class.php';
|
||||
|
||||
if (file_exists($sFileClass)) {
|
||||
require_once($sFileClass);
|
||||
$tm2=microtime(true);
|
||||
dump($sClassName." - \t\t".($tm2-$tm1));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Если класс подходит под шаблон модуля, то загружаем его
|
||||
*/
|
||||
if(preg_match("/^Module(\w+)$/i",$sClassName,$aMatch)) {
|
||||
$sName = ucfirst($aMatch[1]);
|
||||
$sFileClass= Config::get('path.root.server').'/classes/modules/'.strtolower($sName).'/'.$sName.'.class.php';
|
||||
|
||||
if (file_exists($sFileClass)) {
|
||||
require_once($sFileClass);
|
||||
} else {
|
||||
$sFileClass = str_replace('/classes/modules/','/engine/modules/',$sFileClass);
|
||||
if(file_exists($sFileClass)) require_once($sFileClass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Если класс подходит под шаблон класса маппера, то загружаем его
|
||||
*/
|
||||
if (preg_match("/^Module(\w+)\_Mapper(\w+)$/i",$sClassName,$aMatch)) {
|
||||
$sFileClass=Config::get('path.root.server').'/classes/modules/'.strtolower($aMatch[1]).'/mapper/'.$aMatch[2].'.mapper.class.php';
|
||||
if (file_exists($sFileClass)) {
|
||||
require_once($sFileClass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Если класс подходит под шаблон класса маппера плагина, то загружаем его
|
||||
*/
|
||||
if (preg_match("/^Plugin(\w+)\_Module(\w+)\_Mapper(\w+)$/i",$sClassName,$aMatch)) {
|
||||
$sFileClass=Config::get('path.root.server').'/plugins/'.strtolower($aMatch[1]).'/classes/modules/'.strtolower($aMatch[2]).'/mapper/'.$aMatch[3].'.mapper.class.php';
|
||||
if (file_exists($sFileClass)) {
|
||||
require_once($sFileClass);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Если класс подходит под шаблон модуля плагина
|
||||
*/
|
||||
if (preg_match("/^Plugin(\w+)\_Module(\w+)$/i",$sClassName,$aMatch)) {
|
||||
$sFileClass=Config::get('path.root.server').'/plugins/'.strtolower($aMatch[1]).'/classes/modules/'.strtolower($aMatch[2]).'/'.$aMatch[2].'.class.php';
|
||||
if (file_exists($sFileClass)) {
|
||||
require_once($sFileClass);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Загрузка цепочки наследуемых классов
|
||||
*/
|
||||
if (preg_match("/^Plugin(\w+)\_Inherit\_([\w\_]+)$/i",$sClassName,$aMatch)) {
|
||||
$sPlugin=$aMatch[1];
|
||||
$sInheritClass=$aMatch[2];
|
||||
$sParentClass=Engine::getInstance()->Plugin_GetParentInherit($sInheritClass);
|
||||
$aInfo = Engine::GetClassInfo(
|
||||
$sClassName,
|
||||
Engine::CI_CLASSPATH|Engine::CI_INHERIT
|
||||
);
|
||||
if($aInfo[Engine::CI_INHERIT]){
|
||||
$sInheritClass = $aInfo[Engine::CI_INHERIT];
|
||||
$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);
|
||||
}
|
||||
}elseif($aInfo[Engine::CI_CLASSPATH]){
|
||||
require_once $aInfo[Engine::CI_CLASSPATH];
|
||||
}elseif(!class_exists($sClassName)){
|
||||
dump("(autoload $sClassName) Can not load CLASS-file");
|
||||
dump($aInfo);
|
||||
//throw new Exception("(autoload '$sClassName') Can not load CLASS-file");
|
||||
}
|
||||
}
|
||||
?>
|
|
@ -427,4 +427,29 @@ function func_camelize($sStr) {
|
|||
return $sCamelized;
|
||||
}
|
||||
|
||||
|
||||
function func_list_plugins($bAll = false){
|
||||
$sPluginsDir = Config::Get('path.root.server').'/plugins';
|
||||
$sPluginsListFile = $sPluginsDir.'/plugins.dat';
|
||||
$aPlugin = array();
|
||||
if($bAll){
|
||||
$aPluginRaw = array();
|
||||
$aPaths = glob("$aPluginRaw/*", GLOB_ONLYDIR);
|
||||
if($aPaths)
|
||||
foreach($aPaths as $sPath){
|
||||
$aPluginRaw[] = basename($sPath);
|
||||
}
|
||||
}else{
|
||||
$aPluginRaw = @array_map('trim', file($sPluginsListFile));
|
||||
}
|
||||
if($aPluginRaw)
|
||||
foreach($aPluginRaw as $sPlugin){
|
||||
$sPluginXML = "$sPluginsDir/$sPlugin/plugin.xml";
|
||||
if(is_file($sPluginXML)){
|
||||
$aPlugin[] = $sPlugin;
|
||||
}
|
||||
}
|
||||
return $aPlugin;
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in a new issue