예제 #1
0
 /**
  * Автозагрузка файла класса
  *
  * @param   string  $sClassName
  * @return  void
  */
 public function Autoloader($sClassName)
 {
     if ($this->AutoloadIgnoreClass($sClassName)) {
         return;
     }
     $aLog = array('class' => $sClassName, 'time_begin' => microtime(true));
     // * В LS 0.4.1 пропущенна буква "s" в слове Inherits
     if (preg_match('/^Plugin(\\w+)_Inherits_([\\w_]+)/i', $sClassName, $aMatch)) {
         if (preg_match("/^Module(\\w+)\\_Entity(\\w+)\$/i", $aMatch[2])) {
             $sPlugin = $aMatch[1];
             $sInheritClass = $aMatch[2];
             $sParentClass = Engine::getInstance()->Plugin_GetParentInherit($sInheritClass);
             // опять приходится через ж..., исправляем ядро движка
             if (strtolower($sParentClass) == strtolower('Plugin' . $sPlugin . '_' . $sInheritClass)) {
                 $sParentClass = Engine::getInstance()->Plugin_GetParentInherit($sInheritClass);
             }
         } else {
             $sParentClass = str_replace('_Inherits_', '_Inherit_', $sClassName);
         }
         $aLog['code'] = $this->ClassAlias($sParentClass, $sClassName);
         $aLog['mode'] = 'inh';
         $aLog['time_end'] = microtime(true);
         $this->aAutoloaderLog[] = $aLog;
         return;
     }
     $aClassElements = HelperPlugin::ClassNameExplode($sClassName);
     if (isset($aClassElements['Module'])) {
         $sClassDelegate = Engine::getInstance()->Plugin_GetDelegate('module', $aClassElements['Module']);
         //if ($sClassDelegate != $sClassName) {
         if ($sClassDelegate != $sClassName and $sClassDelegate != $aClassElements['Module']) {
             // если класс делегирован и делегат загружен, то ничего не делаем
             if (class_exists($sClassDelegate, false)) {
                 return;
             }
             $sClassName = $sClassDelegate;
             $aClassElements = HelperPlugin::ClassNameExplode($sClassName);
         }
     }
     // Формат именования с автонаследованием - создаем родительский класс
     if (preg_match('/^Plugin(\\w+)_Inherits_([\\w_]+)/', $sClassName, $match)) {
         //$aClassElements = HelperPlugin::ClassNameExplode($sClassName);
         if (!isset($this->aInheritance[$aClassElements['Inherits']])) {
             $sParentClass = $aClassElements['Inherits'];
         } else {
             $sParentClass = $this->aInheritance[$aClassElements['Inherits']];
         }
         // Запоминаем последнего наследника в цепочке
         $this->aInheritance[$aClassElements['Inherits']] = str_replace('_Inherits_', '_', $sClassName);
         // Формируем имя родительского класса
         if (isset($aClassElements['Module']) and !strpos($sParentClass, '_')) {
             $sParentClass = 'Module' . $sParentClass;
             if (!class_exists($sParentClass, false)) {
                 Engine::getInstance()->LoadModule($sParentClass);
             }
         }
         // Создаем "динамический" класс или алиас
         $aLog['code'] = $this->ClassAlias($sParentClass, $sClassName);
         $aLog['mode'] = 'inh';
         if (class_exists($sClassName)) {
             /* nothing */
         }
     } elseif (preg_match('/^Plugin(\\w+)_(\\w+)Entity_(\\w+)/', $sClassName, $match)) {
         $aClassElements['Plugin'] = $match[1];
         $aClassElements['Module'] = $match[2];
         $aClassElements['Entity'] = $match[3];
         if ($aLog['file'] = $this->ClassLoad($aClassElements)) {
             $sParentClass = HelperPlugin::ClassNameImplode($aClassElements, 'Entity');
             // Создаем "динамический" класс или алиас
             $aLog['code'] = $this->ClassAlias($sParentClass, $sClassName);
             $aLog['mode'] = 'old';
         }
     } else {
         $aLog['file'] = $this->ClassLoad($sClassName);
         $aLog['mode'] = 'new';
     }
     $aLog['time_end'] = microtime(true);
     $this->aAutoloaderLog[] = $aLog;
 }