Exemplo n.º 1
0
 public function actionNew($aArgs)
 {
     // Передано ли имя нового плагина
     if (!isset($aArgs[0])) {
         die("The plugin name is not specified.\n");
     }
     $this->_name_under = func_underscore($aArgs[0]);
     $this->_name = func_camelize($this->_name_under);
     $path = strtr($this->_name_under, '/\\', DIRECTORY_SEPARATOR);
     $path = Config::Get('path.application.plugins.server') . '/' . $path;
     if (strpos($path, DIRECTORY_SEPARATOR) === false) {
         $path = '.' . DIRECTORY_SEPARATOR . $path;
     }
     $dir = rtrim(realpath(dirname($path)), '\\/');
     if ($dir === false || !is_dir($dir)) {
         die("The directory '{$path}' is not valid. Please make sure the parent directory exists.\n");
     }
     $sourceDir = realpath(dirname(__FILE__) . '/../protected/plugin');
     if ($sourceDir === false) {
         die("\nUnable to locate the source directory.\n");
     }
     // Создаем массив файлов для функции копирования
     $aList = $this->buildFileList($sourceDir, $path);
     // Парсим имена плагинов и пересоздаем массив
     foreach ($aList as $sName => $aFile) {
         $sTarget = str_replace('Example', $this->_name, $aFile['target']);
         $sTarget = str_replace('example', $this->_name_under, $sTarget);
         $sNewName = str_replace('Example', $this->_name, $sName);
         $sNewName = str_replace('example', $this->_name_under, $sNewName);
         if ($sName != $sNewName) {
             unset($aList[$sName]);
         }
         $aFile['target'] = $sTarget;
         $aList[$sNewName] = $aFile;
         $aList[$sNewName]['callback'] = array($this, 'generatePlugin');
     }
     // Копируем файлы
     $this->copyFiles($aList);
     echo "\nYour plugin has been created successfully under {$path}.\n";
 }
 /**
  * Ставим хук на вызов неизвестного метода и считаем что хотели вызвать метод какого либо модуля.
  * Также обрабатывает различные ORM методы сущности, например
  * <pre>
  * $oUser->Save();
  * $oUser->Delete();
  * </pre>
  * И методы модуля ORM, например
  * <pre>
  *    $this->User_getUserItemsByName('Claus');
  *    $this->User_getUserItemsAll();
  * </pre>
  * @see Engine::_CallModule
  *
  * @param string $sName Имя метода
  * @param array $aArgs Аргументы
  * @return mixed
  */
 public function __call($sName, $aArgs)
 {
     $sNameUnderscore = func_underscore($sName);
     if (preg_match("@^add([a-z]+)\$@i", $sName, $aMatch)) {
         return $this->_AddEntity($aArgs[0]);
     }
     if (preg_match("@^update([a-z]+)\$@i", $sName, $aMatch)) {
         return $this->_UpdateEntity($aArgs[0]);
     }
     if (preg_match("@^save([a-z]+)\$@i", $sName, $aMatch)) {
         return $this->_SaveEntity($aArgs[0]);
     }
     if (preg_match("@^delete([a-z]+)\$@i", $sName, $aMatch) and !strpos($sNameUnderscore, 'items_by_filter')) {
         return $this->_DeleteEntity($aArgs[0]);
     }
     if (preg_match("@^reload([a-z]+)\$@i", $sName, $aMatch)) {
         return $this->_ReloadEntity($aArgs[0]);
     }
     if (preg_match("@^showcolumnsfrom([a-z]+)\$@i", $sName, $aMatch)) {
         return $this->_ShowColumnsFrom($aArgs[0]);
     }
     if (preg_match("@^showprimaryindexfrom([a-z]+)\$@i", $sName, $aMatch)) {
         return $this->_ShowPrimaryIndexFrom($aArgs[0]);
     }
     if (preg_match("@^getchildrenof([a-z]+)\$@i", $sName, $aMatch)) {
         return $this->_GetChildrenOfEntity($aArgs[0]);
     }
     if (preg_match("@^getparentof([a-z]+)\$@i", $sName, $aMatch)) {
         return $this->_GetParentOfEntity($aArgs[0]);
     }
     if (preg_match("@^getdescendantsof([a-z]+)\$@i", $sName, $aMatch)) {
         return $this->_GetDescendantsOfEntity($aArgs[0]);
     }
     if (preg_match("@^getancestorsof([a-z]+)\$@i", $sName, $aMatch)) {
         return $this->_GetAncestorsOfEntity($aArgs[0]);
     }
     if (preg_match("@^loadtreeof([a-z]+)\$@i", $sName, $aMatch)) {
         $sEntityFull = array_key_exists(1, $aMatch) ? $aMatch[1] : null;
         return $this->LoadTree(isset($aArgs[0]) ? $aArgs[0] : array(), $sEntityFull);
     }
     $iEntityPosEnd = 0;
     if (strpos($sNameUnderscore, '_items') >= 3) {
         $iEntityPosEnd = strpos($sNameUnderscore, '_items');
     } else {
         if (strpos($sNameUnderscore, '_by') >= 3) {
             $iEntityPosEnd = strpos($sNameUnderscore, '_by');
         } else {
             if (strpos($sNameUnderscore, '_all') >= 3) {
                 $iEntityPosEnd = strpos($sNameUnderscore, '_all');
             }
         }
     }
     if ($iEntityPosEnd && $iEntityPosEnd > 4) {
         $sEntityName = substr($sNameUnderscore, 4, $iEntityPosEnd - 4);
     } else {
         $sEntityName = func_underscore(Engine::GetModuleName($this)) . '_';
         $sNameUnderscore = substr_replace($sNameUnderscore, $sEntityName, 4, 0);
         $iEntityPosEnd = strlen($sEntityName) - 1 + 4;
     }
     $sNameUnderscore = substr_replace($sNameUnderscore, str_replace('_', '', $sEntityName), 4, $iEntityPosEnd - 4);
     $sEntityName = func_camelize($sEntityName);
     /**
      * getMaxRatingFromUserByFilter() get_max_rating_from_user_by_filter
      */
     if (preg_match("@^get_(max|min|avg|sum)_([a-z][_a-z0-9]*)_from_([a-z][_a-z0-9]*)_by_filter\$@i", func_underscore($sName), $aMatch)) {
         return $this->GetAggregateFunctionByFilter($aMatch[1], $aMatch[2], isset($aArgs[0]) ? $aArgs[0] : array(), func_camelize($aMatch[3]));
     }
     /**
      * getMaxRatingFromUserByStatusAndActive() get_max_rating_from_user_by_status_and_active
      */
     if (preg_match("@^get_(max|min|avg|sum)_([a-z][_a-z0-9]*)_from_([a-z][_a-z0-9]*)_by_([_a-z]+)\$@i", func_underscore($sName), $aMatch)) {
         $aSearchParams = explode('_and_', $aMatch[4]);
         $aSplit = array_chunk($aArgs, count($aSearchParams));
         $aFilter = array_combine($aSearchParams, $aSplit[0]);
         if (isset($aSplit[1][0])) {
             $aFilter = array_merge($aFilter, $aSplit[1][0]);
         }
         return $this->GetAggregateFunctionByFilter($aMatch[1], $aMatch[2], $aFilter, func_camelize($aMatch[3]));
     }
     /**
      * getCountFromUserByFilter() get_count_from_user_by_filter
      */
     if (preg_match("@^get_count_from_([a-z][_a-z0-9]*)_by_filter\$@i", func_underscore($sName), $aMatch)) {
         return $this->GetCountItemsByFilter(isset($aArgs[0]) ? $aArgs[0] : array(), func_camelize($aMatch[1]));
     }
     /**
      * getUserItemsByFilter() get_user_items_by_filter
      */
     if (preg_match("@^get_([a-z]+)((_items)|())_by_filter\$@i", $sNameUnderscore, $aMatch)) {
         if ($aMatch[2] == '_items') {
             return $this->GetItemsByFilter($aArgs[0], $sEntityName);
         } else {
             return $this->GetByFilter($aArgs[0], $sEntityName);
         }
     }
     /**
      * deleteUserItemsByFilter() delete_user_items_by_filter
      */
     if (preg_match("@^delete_([a-z\\_]+)_items_by_filter\$@i", func_underscore($sName), $aMatch)) {
         return $this->DeleteItemsByFilter(isset($aArgs[0]) ? $aArgs[0] : array(), func_camelize($aMatch[1]));
     }
     /**
      * getUserItemsByArrayId() get_user_items_by_array_id
      */
     if (preg_match("@^get_([a-z]+)_items_by_array_([_a-z]+)\$@i", $sNameUnderscore, $aMatch)) {
         return $this->GetItemsByArray(array($aMatch[2] => $aArgs[0]), $sEntityName);
     }
     /**
      * getUserItemsByJoinEntity() get_user_items_by_join_entity
      */
     if (preg_match("@^get_([a-z]+)_items_by_join_entity\$@i", $sNameUnderscore, $aMatch)) {
         return $this->GetItemsByJoinEntity($aArgs[0], $aArgs[1], $aArgs[2], $aArgs[3], $aArgs[4], func_camelize($sEntityName));
     }
     /**
      * getUserByLogin()                    get_user_by_login
      * getUserByLoginAndMail()            get_user_by_login_and_mail
      * getUserItemsByName()                get_user_items_by_name
      * getUserItemsByNameAndActive()    get_user_items_by_name_and_active
      * getUserItemsByDateRegisterGte()    get_user_items_by_date_register_gte        (>=)
      * getUserItemsByProfileNameLike()    get_user_items_by_profile_name_like
      * getUserItemsByCityIdIn()            get_user_items_by_city_id_in
      */
     if (preg_match("@^get_([a-z]+)((_items)|())_by_([_a-z]+)\$@i", $sNameUnderscore, $aMatch)) {
         $aAliases = array('_gte' => ' >=', '_lte' => ' <=', '_gt' => ' >', '_lt' => ' <', '_like' => ' LIKE', '_in' => ' IN');
         $sSearchParams = str_replace(array_keys($aAliases), array_values($aAliases), $aMatch[5]);
         $aSearchParams = explode('_and_', $sSearchParams);
         $aSplit = array_chunk($aArgs, count($aSearchParams));
         $aFilter = array_combine($aSearchParams, $aSplit[0]);
         if (isset($aSplit[1][0])) {
             $aFilter = array_merge($aFilter, $aSplit[1][0]);
         }
         if ($aMatch[2] == '_items') {
             return $this->GetItemsByFilter($aFilter, $sEntityName);
         } else {
             return $this->GetByFilter($aFilter, $sEntityName);
         }
     }
     /**
      * getUserAll()            get_user_all        OR
      * getUserItemsAll()    get_user_items_all
      */
     if (preg_match("@^get_([a-z]+)_all\$@i", $sNameUnderscore, $aMatch) || preg_match("@^get_([a-z]+)_items_all\$@i", $sNameUnderscore, $aMatch)) {
         $aFilter = array();
         if (isset($aArgs[0]) and is_array($aArgs[0])) {
             $aFilter = $aArgs[0];
         }
         return $this->GetItemsByFilter($aFilter, $sEntityName);
     }
     return parent::__call($sName, $aArgs);
 }
Exemplo n.º 3
0
 /**
  * Возвращает информацию о пути до файла класса.
  * Используется в {@link autoload автозагрузке}
  *
  * @static
  * @param LsObject $oObject Объект - модуль, экшен, плагин, хук, сущность
  * @return null|string
  */
 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/' . func_underscore($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';
             if (!is_file($sPath)) {
                 $sPath = str_replace('/classes/modules/', '/engine/modules/', $sPath);
             }
         }
     } elseif ($aInfo[self::CI_MAPPER]) {
         // Маппер
         if ($aInfo[self::CI_PLUGIN]) {
             // Маппер модуля плагина
             $sPath .= 'plugins/' . func_underscore($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';
             if (!is_file($sPath)) {
                 $sPath = str_replace('/classes/modules/', '/engine/modules/', $sPath);
             }
         }
     } elseif ($aInfo[self::CI_ACTION]) {
         // Экшн
         if ($aInfo[self::CI_PLUGIN]) {
             // Экшн плагина
             $sPath .= 'plugins/' . func_underscore($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/' . func_underscore($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/' . func_underscore($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_BLOCK]) {
         // Блок
         if ($aInfo[self::CI_PLUGIN]) {
             // Блок плагина
             $sPath .= 'plugins/' . func_underscore($aInfo[self::CI_PLUGIN]) . '/classes/blocks/Block' . $aInfo[self::CI_BLOCK] . '.class.php';
         } else {
             // Блок ядра
             $sPath .= 'classes/blocks/Block' . $aInfo[self::CI_BLOCK] . '.class.php';
         }
     } elseif ($aInfo[self::CI_PLUGIN]) {
         // Плагин
         $sPath .= 'plugins/' . func_underscore($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;
 }
Exemplo n.º 4
0
 /**
  * Ставим хук на вызов неизвестного метода и считаем что хотели вызвать метод какого либо модуля
  *
  * @param string $sName
  * @param array $aArgs
  * @return unknown
  */
 public function __call($sName, $aArgs)
 {
     $sType = strtolower(substr($sName, 0, 3));
     if (!strpos($sName, '_') and in_array($sType, array('get', 'set'))) {
         $sKey = func_underscore(substr($sName, 3));
         if ($sType == 'get') {
             if (isset($this->_aData[$sKey])) {
                 return $this->_aData[$sKey];
             } else {
                 if (preg_match('/Entity([^_]+)/', get_class($this), $sModulePrefix)) {
                     $sModulePrefix = func_underscore($sModulePrefix[1]) . '_';
                     if (isset($this->_aData[$sModulePrefix . $sKey])) {
                         return $this->_aData[$sModulePrefix . $sKey];
                     }
                 }
             }
             return null;
         } elseif ($sType == 'set' and array_key_exists(0, $aArgs)) {
             $this->_aData[$sKey] = $aArgs[0];
         }
     } else {
         return Engine::getInstance()->_CallModule($sName, $aArgs);
     }
 }
Exemplo n.º 5
0
 /**
  * Проверяет разрешение для конкретного пользователя
  *
  * @param ModuleUser_EntityUser $oUser Пользователь
  * @param string $sPermissionCode Код разрешения
  * @param array $aParams Параметры
  * @param mixed $sPlugin Плагин, можно указать код плагина, название класса или объект
  *
  * @return bool
  */
 protected function IsAllowUserFull($oUser, $sPermissionCode, $aParams = array(), $sPlugin = null)
 {
     if (!$sPermissionCode) {
         return false;
     }
     $sPlugin = $sPlugin ? Plugin::GetPluginCode($sPlugin) : '';
     /**
      * Загружаем все роли и пермишены
      */
     $this->LoadRoleAndPermissions();
     $sUserId = self::ROLE_CODE_GUEST;
     if ($oUser) {
         $sUserId = $oUser->getId();
     }
     /**
      * Смотрим роли в кеше
      */
     if (!isset($this->aUserRoleCache[$sUserId])) {
         if ($sUserId == self::ROLE_CODE_GUEST) {
             $aRoles = $this->GetRoleByCodeAndState(self::ROLE_CODE_GUEST, self::ROLE_STATE_ACTIVE);
             $aRoles = $aRoles ? array($aRoles) : array();
         } else {
             $aRoles = $this->GetRolesByUser($oUser);
         }
         $this->aUserRoleCache[$sUserId] = $aRoles;
     } else {
         $aRoles = $this->aUserRoleCache[$sUserId];
     }
     /**
      * Получаем пермишены для ролей
      */
     $sPermissionCode = func_underscore($sPermissionCode);
     $mResult = false;
     foreach ($aRoles as $oRole) {
         /**
          * У роли есть необходимый пермишен, то проверим на возможную кастомную обработку с параметрами
          */
         if ($this->CheckPermissionByRole($oRole, $sPermissionCode, $sPlugin)) {
             /**
              * Проверяем на передачу коллбека
              */
             if (isset($aParams['callback']) and is_callable($aParams['callback'])) {
                 $mResult = call_user_func($aParams['callback'], $oUser, $aParams);
             } else {
                 /**
                  * Для плагинов: CheckCustomPluginArticleCreate
                  * Для ядра: CheckCustomCreate
                  */
                 $sAdd = $sPlugin ? 'Plugin' . func_camelize($sPlugin) : '';
                 $sMethod = 'CheckCustom' . $sAdd . func_camelize($sPermissionCode);
                 if (method_exists($this, $sMethod)) {
                     $mResult = call_user_func(array($this, $sMethod), $oUser, $aParams);
                 } else {
                     return true;
                 }
             }
             break;
         }
     }
     /**
      * Дефолтное сообщение об ошибке
      */
     $sMsg = 'У вас нет прав на "' . $sPermissionCode . '"';
     /**
      * Проверяем результат кастомной обработки
      */
     if ($mResult === true) {
         return true;
     } elseif (is_string($mResult)) {
         /**
          * Вернули кастомное сообщение об ошибке
          */
         $sMsg = $mResult;
     } else {
         /**
          * Формируем сообщение об ошибке
          */
         if (isset($this->aPermissionCache[$sPlugin][$sPermissionCode])) {
             $aPerm = $this->aPermissionCache[$sPlugin][$sPermissionCode];
             if ($aPerm['msg_error']) {
                 $sMsg = $this->Lang_Get($aPerm['msg_error']);
             } else {
                 $sMsg = 'У вас нет прав на "' . ($aPerm['title'] ? $aPerm['title'] : $aPerm['code']) . '"';
             }
         }
     }
     $this->sMessageLast = $sMsg;
     return false;
 }
 /**
  * Возвращает тип валидатора
  *
  * @return string
  */
 public function getTypeValidator()
 {
     return func_underscore(str_ireplace('ModuleValidate_EntityValidator', '', get_class($this)));
 }
 /**
  * Возвращает имя таблицы для сущности
  *
  * @param EntityORM $oEntity Объект сущности
  * @return string
  */
 public static function GetTableName($oEntity)
 {
     /**
      * Варианты таблиц:
      *    prefix_user -> если модуль совпадает с сущностью
      *    prefix_user_invite -> если модуль не сопадает с сущностью
      * Если сущность плагина:
      *    prefix_pluginname_user
      *    prefix_pluginname_user_invite
      */
     $sClass = Engine::getInstance()->Plugin_GetDelegater('entity', is_object($oEntity) ? get_class($oEntity) : $oEntity);
     $sPluginName = func_underscore(Engine::GetPluginName($sClass));
     $sModuleName = func_underscore(Engine::GetModuleName($sClass));
     $sEntityName = func_underscore(Engine::GetEntityName($sClass));
     if (strpos($sEntityName, $sModuleName) === 0) {
         $sTable = func_underscore($sEntityName);
     } else {
         $sTable = func_underscore($sModuleName) . '_' . func_underscore($sEntityName);
     }
     if ($sPluginName) {
         $sTable = $sPluginName . '_' . $sTable;
     }
     /**
      * Если название таблиц переопределено в конфиге, то возвращаем его
      */
     if (Config::Get('db.table.' . $sTable)) {
         return Config::Get('db.table.' . $sTable);
     } else {
         return Config::Get('db.table.prefix') . $sTable;
     }
 }
Exemplo n.º 8
0
 public function __get($sName)
 {
     // Обработка обращений к обёрткам связей MANY_TO_MANY
     // Если связь загружена, возвращаем объект связи
     if (isset($this->_aManyToManyRelations[func_underscore($sName)])) {
         return $this->_aManyToManyRelations[func_underscore($sName)];
         // Есл не загружена, но связь с таким именем существет, пробуем загрузить и вернуть объект связи
     } elseif (isset($this->aRelations[func_underscore($sName)]) && $this->aRelations[func_underscore($sName)][0] == self::RELATION_TYPE_MANY_TO_MANY) {
         $sMethod = 'get' . func_camelize($sName);
         $this->__call($sMethod, array());
         if (isset($this->_aManyToManyRelations[func_underscore($sName)])) {
             return $this->_aManyToManyRelations[func_underscore($sName)];
         }
         // В противном случае возвращаем то, что просили у объекта
     } else {
         return $this->{$sName};
     }
 }
Exemplo n.º 9
0
 /**
  * Возвращает код плагина
  *
  * @param string|object $mPlugin Объект любого класса плагина или название плагина
  *
  * @return string
  */
 public static function GetPluginCode($mPlugin)
 {
     if (is_object($mPlugin)) {
         $mPlugin = get_class($mPlugin);
     }
     return preg_match('/^Plugin([\\w]+)(_[\\w]+)?$/Ui', $mPlugin, $aMatches) ? func_underscore($aMatches[1]) : func_underscore($mPlugin);
 }
Exemplo n.º 10
0
 /**
  * Возвращает имя таблицы для сущности
  *
  * @param unknown_type $oEntity
  * @return unknown
  */
 public static function GetTableName($oEntity)
 {
     /**
      * Варианты таблиц:
      * 	prefix_user -> если модуль совпадает с сущностью
      * 	prefix_user_invite -> если модуль не сопадает с сущностью
      */
     $sModuleName = func_underscore(Engine::GetModuleName($oEntity));
     $sEntityName = func_underscore(Engine::GetEntityName($oEntity));
     if (strpos($sEntityName, $sModuleName) === 0) {
         $sTable = func_underscore($sEntityName);
     } else {
         $sTable = func_underscore($sModuleName) . '_' . func_underscore($sEntityName);
     }
     if (Config::Get('db.table.' . $sTable)) {
         return Config::Get('db.table.' . $sTable);
     } else {
         return Config::Get('db.table.prefix') . $sTable;
     }
 }
Exemplo n.º 11
0
 /**
  * Возвращает информацию о пути до файла класса.
  * Используется в {@link autoload автозагрузке}
  *
  * @static
  * @param LsObject $oObject Объект - модуль, экшен, плагин, хук, сущность
  * @return null|string
  */
 public static function GetClassPath($oObject)
 {
     $aInfo = self::GetClassInfo($oObject, self::CI_OBJECT);
     $sPath = Config::get('path.application.server') . '/';
     $sPathFramework = Config::get('path.framework.server') . '/';
     if ($aInfo[self::CI_ENTITY]) {
         // Сущность
         if ($aInfo[self::CI_PLUGIN]) {
             // Сущность модуля плагина
             $sPath .= 'plugins/' . func_underscore($aInfo[self::CI_PLUGIN]) . '/classes/modules/' . strtolower($aInfo[self::CI_MODULE]) . '/entity/' . $aInfo[self::CI_ENTITY] . '.entity.class.php';
         } else {
             // Сущность модуля ядра
             $sFile = 'classes/modules/' . strtolower($aInfo[self::CI_MODULE]) . '/entity/' . $aInfo[self::CI_ENTITY] . '.entity.class.php';
             $sPath .= $sFile;
             if (!is_file($sPath)) {
                 $sPath = $sPathFramework . $sFile;
             }
         }
     } elseif ($aInfo[self::CI_BEHAVIOR]) {
         // Поведение
         if ($aInfo[self::CI_PLUGIN]) {
             // Поведение модуля плагина
             $sPath .= 'plugins/' . func_underscore($aInfo[self::CI_PLUGIN]) . '/classes/modules/' . strtolower($aInfo[self::CI_MODULE]) . '/behavior/' . $aInfo[self::CI_BEHAVIOR] . '.behavior.class.php';
         } else {
             // Поведение модуля ядра
             $sFile = 'classes/modules/' . strtolower($aInfo[self::CI_MODULE]) . '/behavior/' . $aInfo[self::CI_BEHAVIOR] . '.behavior.class.php';
             $sPath .= $sFile;
             if (!is_file($sPath)) {
                 $sPath = $sPathFramework . $sFile;
             }
         }
     } elseif ($aInfo[self::CI_MAPPER]) {
         // Маппер
         if ($aInfo[self::CI_PLUGIN]) {
             // Маппер модуля плагина
             $sPath .= 'plugins/' . func_underscore($aInfo[self::CI_PLUGIN]) . '/classes/modules/' . strtolower($aInfo[self::CI_MODULE]) . '/mapper/' . $aInfo[self::CI_MAPPER] . '.mapper.class.php';
         } else {
             // Маппер модуля ядра
             $sFile = 'classes/modules/' . strtolower($aInfo[self::CI_MODULE]) . '/mapper/' . $aInfo[self::CI_MAPPER] . '.mapper.class.php';
             $sPath .= $sFile;
             if (!is_file($sPath)) {
                 $sPath = $sPathFramework . $sFile;
             }
         }
     } elseif ($aInfo[self::CI_EVENT]) {
         // Евент
         if ($aInfo[self::CI_PLUGIN]) {
             // Евент плагина
             $sPath .= 'plugins/' . func_underscore($aInfo[self::CI_PLUGIN]) . '/classes/actions/' . lcfirst($aInfo[self::CI_ACTION]) . '/Event' . $aInfo[self::CI_EVENT] . '.class.php';
         } else {
             // Евент ядра
             $sPath .= 'classes/actions/' . lcfirst($aInfo[self::CI_ACTION]) . '/Event' . $aInfo[self::CI_EVENT] . '.class.php';
         }
     } elseif ($aInfo[self::CI_ACTION]) {
         // Экшн
         if ($aInfo[self::CI_PLUGIN]) {
             // Экшн плагина
             $sPath .= 'plugins/' . func_underscore($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/' . func_underscore($aInfo[self::CI_PLUGIN]) . '/classes/modules/' . strtolower($aInfo[self::CI_MODULE]) . '/' . $aInfo[self::CI_MODULE] . '.class.php';
         } else {
             // Модуль ядра
             $sFile = 'classes/modules/' . strtolower($aInfo[self::CI_MODULE]) . '/' . $aInfo[self::CI_MODULE] . '.class.php';
             $sPath .= $sFile;
             if (!is_file($sPath)) {
                 $sPath = $sPathFramework . $sFile;
             }
         }
     } elseif ($aInfo[self::CI_HOOK]) {
         // Хук
         if ($aInfo[self::CI_PLUGIN]) {
             // Хук плагина
             $sPath .= 'plugins/' . func_underscore($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_BLOCK]) {
         // Блок
         if ($aInfo[self::CI_PLUGIN]) {
             // Блок плагина
             $sPath .= 'plugins/' . func_underscore($aInfo[self::CI_PLUGIN]) . '/classes/blocks/Block' . $aInfo[self::CI_BLOCK] . '.class.php';
         } else {
             // Блок ядра
             $sPath .= 'classes/blocks/Block' . $aInfo[self::CI_BLOCK] . '.class.php';
         }
     } elseif ($aInfo[self::CI_PLUGIN]) {
         // Плагин
         $sPath .= 'plugins/' . func_underscore($aInfo[self::CI_PLUGIN]) . '/Plugin' . $aInfo[self::CI_PLUGIN] . '.class.php';
     } else {
         $sClassName = is_string($oObject) ? $oObject : get_class($oObject);
         $sPath = $sPathFramework . 'classes/engine/' . $sClassName . '.class.php';
     }
     return is_file($sPath) ? $sPath : null;
 }
Exemplo n.º 12
0
 /**
  * Возвращает имя таблицы для сущности
  *
  * @param unknown_type $oEntity
  * @return unknown
  */
 public static function GetTableName($oEntity)
 {
     /**
      * Варианты таблиц:
      * 	prefix_user -> если модуль совпадает с сущностью
      * 	prefix_user_invite -> если модуль не сопадает с сущностью
      */
     $sClass = Engine::getInstance()->Plugin_GetDelegater('entity', is_object($oEntity) ? get_class($oEntity) : $oEntity);
     $sModuleName = func_underscore(Engine::GetModuleName($sClass));
     $sEntityName = func_underscore(Engine::GetEntityName($sClass));
     if (strpos($sEntityName, $sModuleName) === 0) {
         $sTable = func_underscore($sEntityName);
     } else {
         $sTable = func_underscore($sModuleName) . '_' . func_underscore($sEntityName);
     }
     if (Config::Get('db.table.' . $sTable)) {
         return Config::Get('db.table.' . $sTable);
     } else {
         return Config::Get('db.table.prefix') . $sTable;
     }
 }