Changeset 985
- Timestamp:
- 08/19/10 13:02:15 (18 months ago)
- Location:
- trunk/engine
- Files:
-
- 2 modified
-
classes/Engine.class.php (modified) (19 diffs)
-
include/function.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/engine/classes/Engine.class.php
r983 r985 29 29 require_once("Mapper.class.php"); 30 30 31 31 32 /** 32 33 * Основной класс движка, который позволяет напрямую обращаться к любому модулю … … 34 35 */ 35 36 class Engine extends Object { 37 38 /** 39 * Имя плагина 40 * @var int 41 */ 42 const CI_PLUGIN = 1; 43 44 /** 45 * Имя экшна 46 * @var int 47 */ 48 const CI_ACTION = 2; 49 50 /** 51 * Имя модуля 52 * @var int 53 */ 54 const CI_MODULE = 4; 55 56 /** 57 * Имя сущности 58 * @var int 59 */ 60 const CI_ENTITY = 8; 61 62 /** 63 * Имя маппера 64 * @var int 65 */ 66 const CI_MAPPER = 16; 67 68 /** 69 * Имя метода 70 * @var int 71 */ 72 const CI_METHOD = 32; 73 74 /** 75 * Имя хука 76 * @var int 77 */ 78 const CI_HOOK = 64; 79 80 /** 81 * Имя класс наследования 82 * @var int 83 */ 84 const CI_INHERIT = 128; 85 86 /** 87 * Префикс плагина 88 * @var int 89 */ 90 const CI_PPREFIX = 8192; 91 92 /** 93 * Разобранный класс наследования 94 * @var int 95 */ 96 const CI_INHERITS = 16384; 97 98 /** 99 * Путь к файлу класса 100 * @var int 101 */ 102 const CI_CLASSPATH = 32768; 103 104 /** 105 * Все свойства класса 106 * @var int 107 */ 108 const CI_ALL = 65535; 109 110 /** 111 * Свойства по-умолчанию 112 * CI_ALL ^ (CI_CLASSPATH | CI_INHERITS | CI_PPREFIX) 113 * @var int 114 */ 115 const CI_DEFAULT = 8191; 116 117 /** 118 * Объекты 119 * CI_ACTION | CI_MAPPER | CI_HOOK | CI_PLUGIN | CI_ACTION | CI_MODULE | CI_ENTITY 120 * @var int 121 */ 122 const CI_OBJECT = 95; 36 123 37 124 static protected $oInstance=null; … … 121 208 $oProfiler=ProfilerSimple::getInstance(); 122 209 $iTimeId=$oProfiler->Start('InitModule',get_class($oModule)); 123 210 124 211 $this->InitModule($oModule); 125 212 … … 131 218 /** 132 219 * Инициализирует модуль 133 * 220 * 134 221 * @param unknown_type $oModule 135 */ 136 protected function InitModule($oModule){ 137 $sOrigClassName = $sClassName = get_class($oModule); 222 * @param unknown_type $bHookParent 223 */ 224 protected function InitModule($oModule, $bHookParent = true){ 225 $sOrigClassName = $sClassName = get_class($oModule); 138 226 $bRunHooks = false; 139 227 140 228 if($this->isInitModule('ModuleHook')){ 141 229 $bRunHooks = true; 142 while(preg_match('#^Plugin#i', $sClassName)){ 143 $sParentClassName = get_parent_class($sClassName); 144 if($sParentClassName == 'Module'){ 145 break; 230 if($bHookParent){ 231 while(self::GetPluginName($sClassName)){ 232 $sParentClassName = get_parent_class($sClassName); 233 if(!self::GetClassInfo($sParentClassName, self::CI_MODULE, true)){ 234 break; 235 } 236 $sClassName = $sParentClassName; 146 237 } 147 $sClassName = $sParentClassName; 148 } 149 } 150 238 } 239 } 151 240 if($bRunHooks || $sClassName == 'ModuleHook'){ 152 241 $sHookPrefix = 'module_'; 153 if($sPluginName = self::GetPluginName($sClassName)) {242 if($sPluginName = self::GetPluginName($sClassName)){ 154 243 $sHookPrefix .= "plugin{$sPluginName}_"; 155 244 } 156 245 $sHookPrefix .= self::GetModuleName($sClassName).'_init_'; 157 246 } 158 159 247 if($bRunHooks){ 160 248 $this->Hook_Run($sHookPrefix.'before'); 161 249 } 162 250 $oModule->Init(); 163 $oModule->SetInit(); 251 $oModule->SetInit(); 164 252 if($bRunHooks || $sClassName == 'ModuleHook'){ 165 253 $this->Hook_Run($sHookPrefix.'after'); 166 } 254 } 167 255 } 168 256 … … 200 288 } 201 289 } 290 202 291 /** 203 292 * Выполняет загрузку модуля по его названию … … 256 345 if($aFiles and count($aFiles)) { 257 346 foreach ($aFiles as $sFile) { 258 if (preg_match("/Hook([ \w]+)\.class\.php$/i",basename($sFile),$aMatch)) {259 require_once($sFile);347 if (preg_match("/Hook([^_]+)\.class\.php$/i",basename($sFile),$aMatch)) { 348 //require_once($sFile); 260 349 $sClassName='Hook'.$aMatch[1]; 261 350 $oHook=new $sClassName; … … 276 365 */ 277 366 protected function InitPluginHooks() { 278 if($aPluginList = @file(Config::Get('path.root.server').'/plugins/plugins.dat')) { 279 $aPluginList=array_map('trim',$aPluginList); 367 if($aPluginList = func_list_plugins()) { 280 368 281 369 $aFiles=array(); … … 286 374 if($aFiles and count($aFiles)) { 287 375 foreach ($aFiles as $sFile) { 288 if (preg_match("/Hook([ \w]+)\.class\.php$/i",basename($sFile),$aMatch)) {289 require_once($sFile);376 if (preg_match("/Hook([^_]+)\.class\.php$/i",basename($sFile),$aMatch)) { 377 //require_once($sFile); 290 378 $sPluginName = ucfirst($sPluginName); 291 379 $sClassName="Plugin{$sPluginName}_Hook{$aMatch[1]}"; … … 304 392 */ 305 393 protected function LoadPlugins() { 306 if($aPluginList = @file(Config::Get('path.root.server').'/plugins/plugins.dat')) { 307 $aPluginList=array_map('trim',$aPluginList); 308 394 if($aPluginList = func_list_plugins()) { 309 395 foreach ($aPluginList as $sPluginName) { 310 $sDirPlugins=Config::Get('path.root.server').'/plugins/'; 311 $sPluginNameClass='Plugin'.ucfirst($sPluginName); 312 $sFile="{$sDirPlugins}{$sPluginName}/{$sPluginNameClass}.class.php"; 313 if(is_file($sFile)) { 314 require_once($sFile); 315 $sClassName="{$sPluginNameClass}"; 316 $oPlugin=new $sClassName; 317 $oPlugin->Delegate(); 318 $this->aPlugins[$sPluginName]=$oPlugin; 319 } 396 $sClassName='Plugin'.ucfirst($sPluginName); 397 $oPlugin=new $sClassName; 398 $oPlugin->Delegate(); 399 $this->aPlugins[$sPluginName]=$oPlugin; 320 400 } 321 401 } … … 347 427 * @return mixed 348 428 */ 349 public function isFileExists($sFile,$iTime=3600) { return file_exists($sFile); 350 if (strpos($sFile,'/Cache.class.')!==false) { 351 return file_exists($sFile); 352 } 353 if (SYS_CACHE_USE and SYS_CACHE_TYPE==SYS_CACHE_TYPE_MEMORY) { 354 if (false === ($data = $this->Cache_Get("file_exists_{$sFile}"))) { 355 $data=file_exists($sFile); 356 $this->Cache_Set((int)$data, "file_exists_{$sFile}", array(), $iTime); 357 } 358 return $data; 359 } else { 360 return file_exists($sFile); 361 } 429 public function isFileExists($sFile,$iTime=3600) { 430 // пока так 431 return file_exists($sFile); 432 433 if( 434 !$this->isInit('cache') 435 || !Config::Get('sys.cache.use') 436 || Config::Get('sys.cache.type') != 'memory' 437 ){ 438 return file_exists($sFile); 439 } 440 if (false === ($data = $this->Cache_Get("file_exists_{$sFile}"))) { 441 $data=file_exists($sFile); 442 $this->Cache_Set((int)$data, "file_exists_{$sFile}", array(), $iTime); 443 } 444 return $data; 362 445 } 363 446 /** … … 369 452 */ 370 453 public function _CallModule($sName,$aArgs) { 371 $sArgs='';372 $aStrArgs=array();373 foreach ($aArgs as $sKey => $arg) {374 $aStrArgs[]='$aArgs['.$sKey.']';375 }376 $sArgs=join(',',$aStrArgs);377 378 454 list($oModule,$sModuleName,$sMethod)=$this->GetModule($sName); 379 455 … … 420 496 * Поддержка полного синтаксиса при вызове метода модуля 421 497 */ 422 if (preg_match("/^Plugin(\w+)\_Module(\w+)\_(\w+)$/i",$sName,$aMatch)) { 423 $sName="Plugin{$aMatch[1]}_{$aMatch[2]}_{$aMatch[3]}"; 424 } 425 if (preg_match("/^Module(\w+)\_(\w+)$/i",$sName,$aMatch)) { 426 $sName="{$aMatch[1]}_{$aMatch[2]}"; 427 } 498 $aInfo = self::GetClassInfo( 499 $sName, 500 self::CI_MODULE 501 |self::CI_PPREFIX 502 |self::CI_METHOD 503 ); 504 if($aInfo[self::CI_MODULE] && $aInfo[self::CI_METHOD]){ 505 $sName = $aInfo[self::CI_MODULE].'_'.$aInfo[self::CI_METHOD]; 506 if($aInfo[self::CI_PPREFIX]){ 507 $sName = $aInfo[self::CI_PPREFIX].$sName; 508 } 509 } 510 428 511 $aName=explode("_",$sName); 429 512 … … 432 515 $sModuleClass='Module'.$aName[0]; 433 516 $sMethod=$aName[1]; 434 } else {517 } elseif (count($aName)==3) { 435 518 $sModuleName=$aName[0].'_'.$aName[1]; 436 519 $sModuleClass=$aName[0].'_Module'.$aName[1]; 437 520 $sMethod=$aName[2]; 521 } else { 522 throw new Exception("Undefined method module: ".$sName); 438 523 } 439 524 /** 440 525 * Подхватыем делегат модуля (в случае наличия такового) 441 526 */ 442 if(!in_array($sModuleName,array('Plugin','Hook'))) $sModuleClass=$this->Plugin_GetDelegate('module',$sModuleClass); 527 if(!in_array($sModuleName,array('Plugin','Hook'))){ 528 $sModuleClass=$this->Plugin_GetDelegate('module',$sModuleClass); 529 } 443 530 444 531 if (isset($this->aModules[$sModuleClass])) { … … 471 558 472 559 /** 473 * Блокируем копирование/клонирование объекта роутинга560 * Блокируем копирование/клонирование объекта ядра 474 561 * 475 562 */ … … 486 573 */ 487 574 public static function GetMapper($sClassName,$sName=null,$oConnect=null) { 488 if (preg_match("/^(?:Plugin\w+_)?Module(\w+)$/i",$sClassName,$aMatch)) { 575 $sModuleName = self::GetClassInfo( 576 $sClassName, 577 self::CI_MODULE, 578 true 579 ); 580 if ($sModuleName) { 489 581 if (!$sName) { 490 $sName=$ aMatch[1];582 $sName=$sModuleName; 491 583 } 492 584 $sClass=$sClassName.'_Mapper'.$sName; … … 517 609 break; 518 610 519 case 1: 611 case 1: 520 612 /** 521 613 * Поддержка полного синтаксиса при вызове сущности 522 614 */ 523 if (preg_match("/^Module(\w+)\_Entity(\w+)$/i",$sName,$aMatch)) { 524 $sName="{$aMatch[1]}_{$aMatch[2]}"; 615 $aInfo = self::GetClassInfo( 616 $sName, 617 self::CI_ENTITY 618 |self::CI_MODULE 619 |self::CI_PLUGIN 620 ); 621 if ($aInfo[self::CI_MODULE] 622 && $aInfo[self::CI_ENTITY]) { 623 $sName=$aInfo[self::CI_MODULE].'_'.$aInfo[self::CI_ENTITY]; 525 624 } 526 625 … … 530 629 * PluginTest_Test -> PluginTest_ModuleTest_EntityTest 531 630 */ 532 if( substr($sModule,0,6)=='Plugin' and strlen($sModule)>6) {533 $sPlugin = substr($sModule,6);631 if($aInfo[self::CI_PLUGIN]) { 632 $sPlugin = $aInfo[self::CI_PLUGIN]; 534 633 $sModule = $sEntity; 535 634 } … … 540 639 * Поддержка полного синтаксиса при вызове сущности плагина 541 640 */ 542 if (preg_match("/^Plugin(\w+)\_Module(\w+)\_Entity(\w+)$/i",$sName,$aMatch)) { 543 $sName="Plugin{$aMatch[1]}_{$aMatch[2]}_{$aMatch[3]}"; 641 $aInfo = self::GetClassInfo( 642 $sName, 643 self::CI_ENTITY 644 |self::CI_MODULE 645 |self::CI_PLUGIN 646 ); 647 if ($aInfo[self::CI_PLUGIN] 648 && $aInfo[self::CI_MODULE] 649 && $aInfo[self::CI_ENTITY]) { 650 $sName='Plugin'.$aInfo[self::CI_PLUGIN] 651 .'_'.$aInfo[self::CI_MODULE] 652 .'_'.$aInfo[self::CI_ENTITY] 653 ; 544 654 } 545 655 /** 546 656 * Entity плагина 547 657 */ 548 if( substr($sName,0,6)=='Plugin') {549 list( $sPlugin,$sModule,$sEntity)=explode('_',$sName);550 $sPlugin = substr($sPlugin,6);658 if($aInfo[self::CI_PLUGIN]) { 659 list(,$sModule,$sEntity)=explode('_',$sName); 660 $sPlugin = $aInfo[self::CI_PLUGIN]; 551 661 } else { 552 662 throw new Exception("Unknown entity '{$sName}' given."); … … 572 682 573 683 574 575 public static function GetPluginName($oModule) { 576 if (preg_match('/Plugin([^_]+)/',is_string($oModule) ? $oModule : get_class($oModule),$aMatches)) { 577 if(isset($aMatches[1])) { 578 return $aMatches[1]; 579 } 580 } 581 return null; 684 public static function GetPluginName($oModule) { 685 return self::GetClassInfo($oModule, self::CI_PLUGIN, true); 582 686 } 583 687 584 688 public static function GetPluginPrefix($oModule) { 585 if($sPluginName = self::GetPluginName($oModule)) { 586 return 'Plugin'.$sPluginName.'_'; 587 } 588 return ''; 689 return self::GetClassInfo($oModule, self::CI_PPREFIX, true); 589 690 } 590 691 591 692 public static function GetModuleName($oModule) { 592 if (preg_match('/Module([^_]+)/',is_string($oModule) ? $oModule : get_class($oModule),$aMatches)) { 593 if(isset($aMatches[1])) { 594 return $aMatches[1]; 595 } 596 } 597 return null; 693 return self::GetClassInfo($oModule, self::CI_MODULE, true); 598 694 } 599 695 600 696 public static function GetEntityName($oEntity) { 601 if (preg_match('/Entity([^_]+)/',is_string($oEntity) ? $oEntity : get_class($oEntity),$aMatches)) { 602 if(isset($aMatches[1])) { 603 return $aMatches[1]; 604 } 605 } 606 return null; 607 } 697 return self::GetClassInfo($oEntity, self::CI_ENTITY, true); 698 } 699 700 public static function GetActionName($oAction) { 701 return self::GetClassInfo($oAction, self::CI_ACTION, true); 702 } 703 704 public static function GetClassInfo($oObject,$iFlag=self::CI_DEFAULT,$bSingle=false){ 705 $sClassName = is_string($oObject) ? $oObject : get_class($oObject); 706 $aResult = array(); 707 if($iFlag & self::CI_PLUGIN){ 708 $aResult[self::CI_PLUGIN] = preg_match('/^Plugin([^_]+)/',$sClassName,$aMatches) 709 ? $aMatches[1] 710 : null 711 ; 712 } 713 if($iFlag & self::CI_ACTION){ 714 $aResult[self::CI_ACTION] = preg_match('/^(?:Plugin[^_]+_|)Action([^_]+)/',$sClassName,$aMatches) 715 ? $aMatches[1] 716 : null 717 ; 718 } 719 if($iFlag & self::CI_MODULE){ 720 $aResult[self::CI_MODULE] = preg_match('/^(?:Plugin[^_]+_|)Module(?:ORM|)([^_]+)/',$sClassName,$aMatches) 721 ? $aMatches[1] 722 : null 723 ; 724 } 725 if($iFlag & self::CI_ENTITY){ 726 $aResult[self::CI_ENTITY] = preg_match('/_Entity(?:ORM|)([^_]+)/',$sClassName,$aMatches) 727 ? $aMatches[1] 728 : null 729 ; 730 } 731 if($iFlag & self::CI_MAPPER){ 732 $aResult[self::CI_MAPPER] = preg_match('/_Mapper(?:ORM|)([^_]+)/',$sClassName,$aMatches) 733 ? $aMatches[1] 734 : null 735 ; 736 } 737 if($iFlag & self::CI_HOOK){ 738 $aResult[self::CI_HOOK] = preg_match('/^(?:Plugin[^_]+_|)Hook([^_]+)$/',$sClassName,$aMatches) 739 ? $aMatches[1] 740 : null 741 ; 742 } 743 if($iFlag & self::CI_METHOD){ 744 $sModuleName = isset($aResult[self::CI_MODULE]) 745 ? $aResult[self::CI_MODULE] 746 : self::GetClassInfo($sClassName, self::CI_MODULE, true) 747 ; 748 $aResult[self::CI_METHOD] = preg_match('/_([^_]+)$/',$sClassName,$aMatches) 749 ? ($sModuleName && strtolower($aMatches[1]) == strtolower('module'.$sModuleName) 750 ? null 751 : $aMatches[1] 752 ) 753 : null 754 ; 755 } 756 if($iFlag & self::CI_PPREFIX){ 757 $sPluginName = isset($aResult[self::CI_PLUGIN]) 758 ? $aResult[self::CI_PLUGIN] 759 : self::GetClassInfo($sClassName, self::CI_PLUGIN, true) 760 ; 761 $aResult[self::CI_PPREFIX] = $sPluginName 762 ? "Plugin{$sPluginName}_" 763 : '' 764 ; 765 } 766 if($iFlag & self::CI_INHERIT){ 767 $aResult[self::CI_INHERIT] = preg_match('/_Inherits?_(\w+)$/',$sClassName,$aMatches) 768 ? $aMatches[1] 769 : null 770 ; 771 } 772 if($iFlag & self::CI_INHERITS){ 773 $sInherit = isset($aResult[self::CI_INHERIT]) 774 ? $aResult[self::CI_INHERIT] 775 : self::GetClassInfo($sClassName, self::CI_INHERIT, true) 776 ; 777 $aResult[self::CI_INHERITS] = $sInherit 778 ? self::GetClassInfo( 779 $sClassName, 780 self::CI_OBJECT, 781 false) 782 : null 783 ; 784 } 785 if($iFlag & self::CI_CLASSPATH){ 786 $aResult[self::CI_CLASSPATH] = self::GetClassPath($sClassName); 787 } 788 789 return $bSingle ? array_pop($aResult) : $aResult; 790 } 791 792 793 public static function GetClassPath($oObject){ 794 $aInfo = self::GetClassInfo( 795 $oObject, 796 self::CI_OBJECT 797 ); 798 $sPath = Config::get('path.root.server').'/'; 799 if($aInfo[self::CI_ENTITY]){ 800 // Сущность 801 if($aInfo[self::CI_PLUGIN]){ 802 // Сущность модуля плагина 803 $sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN]) 804 .'/classes/modules/'.strtolower($aInfo[self::CI_MODULE]) 805 .'/entity/'.$aInfo[self::CI_ENTITY].'.entity.class.php' 806 ; 807 }else{ 808 // Сущность модуля ядра 809 $sPath .= 'classes/modules/'.strtolower($aInfo[self::CI_MODULE]) 810 .'/entity/'.$aInfo[self::CI_ENTITY].'.entity.class.php' 811 ; 812 } 813 }elseif($aInfo[self::CI_MAPPER]){ 814 // Маппер 815 if($aInfo[self::CI_PLUGIN]){ 816 // Маппер модуля плагина 817 $sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN]) 818 .'/classes/modules/'.strtolower($aInfo[self::CI_MODULE]) 819 .'/mapper/'.$aInfo[self::CI_MAPPER].'.mapper.class.php' 820 ; 821 }else{ 822 // Маппер модуля ядра 823 $sPath .= 'classes/modules/'.strtolower($aInfo[self::CI_MODULE]) 824 .'/mapper/'.$aInfo[self::CI_MAPPER].'.mapper.class.php' 825 ; 826 } 827 }elseif($aInfo[self::CI_ACTION]){ 828 // Экшн 829 if($aInfo[self::CI_PLUGIN]){ 830 // Экшн плагина 831 $sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN]) 832 .'/classes/actions/Action'.$aInfo[self::CI_ACTION].'.class.php' 833 ; 834 }else{ 835 // Экшн ядра 836 $sPath .= 'classes/actions/Action' 837 .$aInfo[self::CI_ACTION].'.class.php' 838 ; 839 } 840 }elseif($aInfo[self::CI_MODULE]){ 841 // Модуль 842 if($aInfo[self::CI_PLUGIN]){ 843 // Модуль плагина 844 $sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN]) 845 .'/classes/modules/'.strtolower($aInfo[self::CI_MODULE]) 846 .'/'.$aInfo[self::CI_MODULE].'.class.php'; 847 ; 848 }else{ 849 // Модуль ядра 850 $sPath .= 'classes/modules/'.strtolower($aInfo[self::CI_MODULE]) 851 .'/'.$aInfo[self::CI_MODULE].'.class.php' 852 ; 853 if(!is_file($sPath)){ 854 $sPath = str_replace('/classes/modules/','/engine/modules/',$sPath); 855 } 856 } 857 }elseif($aInfo[self::CI_HOOK]){ 858 // Хук 859 if($aInfo[self::CI_PLUGIN]){ 860 // Хук плагина 861 $sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN]) 862 .'/classes/hooks/Hook'.$aInfo[self::CI_HOOK] 863 .'.class.php'; 864 ; 865 }else{ 866 // Хук ядра 867 $sPath .= 'classes/hooks/Hook'.$aInfo[self::CI_HOOK].'.class.php'; 868 } 869 }elseif($aInfo[self::CI_PLUGIN]){ 870 // Плагин 871 $sPath .= 'plugins/'.strtolower($aInfo[self::CI_PLUGIN]) 872 .'/Plugin'.$aInfo[self::CI_PLUGIN] 873 .'.class.php'; 874 ; 875 }else{ 876 $sClassName = is_string($oObject) ? $oObject : get_class($oObject); 877 $sPath .= 'engine/classes/'.$sClassName.'.class.php'; 878 } 879 return is_file($sPath) ? $sPath : null; 880 } 881 882 608 883 } 609 884 610 885 /** 611 * Автозагрузка к слассов886 * Автозагрузка классов 612 887 * 613 888 * @param unknown_type $sClassName 614 889 */ 615 890 function __autoload($sClassName) { 616 /** 617 * Если класс подходит под шаблон класса сущности то загружаем его 618 */ 619 if (preg_match("/^Module(\w+)\_Entity(\w+)$/i",$sClassName,$aMatch)) { 620 $tm1=microtime(true); 621 622 $sFileClass=Config::get('path.root.server').'/classes/modules/'.strtolower($aMatch[1]).'/entity/'.$aMatch[2].'.entity.class.php'; 623 624 if (file_exists($sFileClass)) { 625 require_once($sFileClass); 626 $tm2=microtime(true); 627 dump($sClassName." - \t\t".($tm2-$tm1)); 628 } 629 } 630 631 /** 632 * Если класс подходит под шаблон класса сущности плагина 633 */ 634 if (preg_match("/^Plugin(\w+)\_Module(\w+)\_Entity(\w+)$/i",$sClassName,$aMatch)) { 635 $tm1=microtime(true); 636 637 $sFileClass= Config::get('path.root.server').'/plugins/'.strtolower($aMatch[1]).'/classes/modules/'.strtolower($aMatch[2]).'/entity/'.$aMatch[3].'.entity.class.php'; 638 639 if (file_exists($sFileClass)) { 640 require_once($sFileClass); 641 $tm2=microtime(true); 642 dump($sClassName." - \t\t".($tm2-$tm1)); 643 } 644 } 645 646 /** 647 * Если класс подходит под шаблон модуля, то загружаем его 648 */ 649 if(preg_match("/^Module(\w+)$/i",$sClassName,$aMatch)) { 650 $sName = ucfirst($aMatch[1]); 651 $sFileClass= Config::get('path.root.server').'/classes/modules/'.strtolower($sName).'/'.$sName.'.class.php'; 652 653 if (file_exists($sFileClass)) { 654 require_once($sFileClass); 655 } else { 656 $sFileClass = str_replace('/classes/modules/','/engine/modules/',$sFileClass); 657 if(file_exists($sFileClass)) require_once($sFileClass); 658 } 659 } 660 661 /** 662 * Если класс подходит под шаблон класса маппера, то загружаем его 663 */ 664 if (preg_match("/^Module(\w+)\_Mapper(\w+)$/i",$sClassName,$aMatch)) { 665 $sFileClass=Config::get('path.root.server').'/classes/modules/'.strtolower($aMatch[1]).'/mapper/'.$aMatch[2].'.mapper.class.php'; 666 if (file_exists($sFileClass)) { 667 require_once($sFileClass); 668 } 669 } 670 671 /** 672 * Если класс подходит под шаблон класса маппера плагина, то загружаем его 673 */ 674 if (preg_match("/^Plugin(\w+)\_Module(\w+)\_Mapper(\w+)$/i",$sClassName,$aMatch)) { 675 $sFileClass=Config::get('path.root.server').'/plugins/'.strtolower($aMatch[1]).'/classes/modules/'.strtolower($aMatch[2]).'/mapper/'.$aMatch[3].'.mapper.class.php'; 676 if (file_exists($sFileClass)) { 677 require_once($sFileClass); 678 } 679 } 680 681 /** 682 * Если класс подходит под шаблон модуля плагина 683 */ 684 if (preg_match("/^Plugin(\w+)\_Module(\w+)$/i",$sClassName,$aMatch)) { 685 $sFileClass=Config::get('path.root.server').'/plugins/'.strtolower($aMatch[1]).'/classes/modules/'.strtolower($aMatch[2]).'/'.$aMatch[2].'.class.php'; 686 if (file_exists($sFileClass)) { 687 require_once($sFileClass); 688 } 689 } 690 691 692 /** 693 * Загрузка цепочки наследуемых классов 694 */ 695 if (preg_match("/^Plugin(\w+)\_Inherit\_([\w\_]+)$/i",$sClassName,$aMatch)) { 696 $sPlugin=$aMatch[1]; 697 $sInheritClass=$aMatch[2]; 698 $sParentClass=Engine::getInstance()->Plugin_GetParentInherit($sInheritClass); 891 $aInfo = Engine::GetClassInfo( 892 $sClassName, 893 Engine::CI_CLASSPATH|Engine::CI_INHERIT 894 ); 895 if($aInfo[Engine::CI_INHERIT]){ 896 $sInheritClass = $aInfo[Engine::CI_INHERIT]; 897 $sParentClass = Engine::getInstance()->Plugin_GetParentInherit($sInheritClass); 699 898 class_alias($sParentClass,$sClassName); 700 } 701 702 /** 703 * Загрузка класса экшена 704 */ 705 if (preg_match("/^Action(\w+)$/i",$sClassName,$aMatch)) { 706 $sFileClass=Config::get('path.root.server').'/classes/actions/'.$sClassName.'.class.php'; 707 if (file_exists($sFileClass)) { 708 require_once($sFileClass); 709 } 710 } 711 712 /** 713 * Загрузка класса экшена плагина 714 */ 715 if (preg_match("/^Plugin(\w+)\_Action(\w+)$/i",$sClassName,$aMatch)) { 716 $sFileClass=Config::get('path.root.server').'/plugins/'.strtolower($aMatch[1]).'/classes/actions/Action'.$aMatch[2].'.class.php'; 717 if (file_exists($sFileClass)) { 718 require_once($sFileClass); 719 } 899 }elseif($aInfo[Engine::CI_CLASSPATH]){ 900 require_once $aInfo[Engine::CI_CLASSPATH]; 901 }elseif(!class_exists($sClassName)){ 902 dump("(autoload $sClassName) Can not load CLASS-file"); 903 dump($aInfo); 904 //throw new Exception("(autoload '$sClassName') Can not load CLASS-file"); 720 905 } 721 906 } -
trunk/engine/include/function.php
r980 r985 428 428 } 429 429 430 431 function func_list_plugins($bAll = false){ 432 $sPluginsDir = Config::Get('path.root.server').'/plugins'; 433 $sPluginsListFile = $sPluginsDir.'/plugins.dat'; 434 $aPlugin = array(); 435 if($bAll){ 436 $aPluginRaw = array(); 437 $aPaths = glob("$aPluginRaw/*", GLOB_ONLYDIR); 438 if($aPaths) 439 foreach($aPaths as $sPath){ 440 $aPluginRaw[] = basename($sPath); 441 } 442 }else{ 443 $aPluginRaw = @array_map('trim', file($sPluginsListFile)); 444 } 445 if($aPluginRaw) 446 foreach($aPluginRaw as $sPlugin){ 447 $sPluginXML = "$sPluginsDir/$sPlugin/plugin.xml"; 448 if(is_file($sPluginXML)){ 449 $aPlugin[] = $sPlugin; 450 } 451 } 452 return $aPlugin; 453 } 454 430 455 ?>
