コード例 #1
0
ファイル: Engine.class.php プロジェクト: anp135/altocms
 /**
  * Возвращает информацию о пути до файла класса.
  * Используется в {@link autoload автозагрузке}
  *
  * @static
  *
  * @param LsObject|string $oObject Объект - модуль, экшен, плагин, хук, сущность
  * @param int             $iArea   В какой области проверять (классы движка, общие классы, плагины)
  *
  * @return null|string
  */
 public static function GetClassPath($oObject, $iArea = self::CI_AREA_ACTUAL)
 {
     $aInfo = static::GetClassInfo($oObject, self::CI_OBJECT);
     $sPluginDir = '';
     if ($aInfo[self::CI_PLUGIN]) {
         $sPlugin = F::StrUnderscore($aInfo[self::CI_PLUGIN]);
         $aPlugins = F::GetPluginsList($iArea & self::CI_AREA_ALL_PLUGINS, false);
         if (isset($aPlugins[$sPlugin]['dirname'])) {
             $sPluginDir = $aPlugins[$sPlugin]['dirname'];
         } else {
             $sPluginDir = $sPlugin;
         }
     }
     $aPathSeek = Config::Get('path.root.seek');
     if ($aInfo[self::CI_ENTITY]) {
         // Сущность
         if ($aInfo[self::CI_PLUGIN]) {
             // Сущность модуля плагина
             $sFile = 'plugins/' . $sPluginDir . '/classes/modules/' . F::StrUnderscore($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';
         }
     } elseif ($aInfo[self::CI_MAPPER]) {
         // Маппер
         if ($aInfo[self::CI_PLUGIN]) {
             // Маппер модуля плагина
             $sFile = 'plugins/' . $sPluginDir . '/classes/modules/' . F::StrUnderscore($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';
         }
     } elseif ($aInfo[self::CI_ACTION]) {
         // Экшн
         if ($aInfo[self::CI_PLUGIN]) {
             // Экшн плагина
             $sFile = 'plugins/' . $sPluginDir . '/classes/actions/Action' . $aInfo[self::CI_ACTION] . '.class.php';
         } else {
             // Экшн ядра
             $sFile = 'classes/actions/Action' . $aInfo[self::CI_ACTION] . '.class.php';
         }
     } elseif ($aInfo[self::CI_MODULE]) {
         // Модуль
         if ($aInfo[self::CI_PLUGIN]) {
             // Модуль плагина
             $sFile = 'plugins/' . $sPluginDir . '/classes/modules/' . F::StrUnderscore($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';
         }
     } elseif ($aInfo[self::CI_HOOK]) {
         // Хук
         if ($aInfo[self::CI_PLUGIN]) {
             // Хук плагина
             $sFile = 'plugins/' . $sPluginDir . '/classes/hooks/Hook' . $aInfo[self::CI_HOOK] . '.class.php';
         } else {
             // Хук ядра
             $sFile = 'classes/hooks/Hook' . $aInfo[self::CI_HOOK] . '.class.php';
         }
     } elseif ($aInfo[self::CI_BLOCK]) {
         // LS-compatible
         if ($aInfo[self::CI_PLUGIN]) {
             // Блок плагина
             $sFile = 'plugins/' . $sPluginDir . '/classes/blocks/Block' . $aInfo[self::CI_BLOCK] . '.class.php';
         } else {
             // Блок ядра
             $sFile = 'classes/blocks/Block' . $aInfo[self::CI_BLOCK] . '.class.php';
         }
     } elseif ($aInfo[self::CI_WIDGET]) {
         // Виджет
         if ($aInfo[self::CI_PLUGIN]) {
             // Виджет плагина
             $sFile = 'plugins/' . $sPluginDir . '/classes/widgets/Widget' . $aInfo[self::CI_WIDGET] . '.class.php';
         } else {
             // Блок ядра
             $sFile = 'classes/widgets/Widget' . $aInfo[self::CI_WIDGET] . '.class.php';
         }
     } elseif ($aInfo[self::CI_PLUGIN]) {
         // Плагин
         $sFile = 'plugins/' . $sPluginDir . '/Plugin' . $aInfo[self::CI_PLUGIN] . '.class.php';
     } else {
         $sClassName = is_string($oObject) ? $oObject : get_class($oObject);
         $sFile = $sClassName . '.class.php';
         $aPathSeek = array(Config::Get('path.dir.engine') . '/classes/core/', Config::Get('path.dir.engine') . '/classes/abstract/');
     }
     $sPath = F::File_Exists($sFile, $aPathSeek);
     return $sPath ? $sPath : null;
 }
コード例 #2
0
ファイル: Plugin.class.php プロジェクト: ZeoNish/altocms
 /**
  * Returns normalized dirname of plugin
  *
  * @param object|string $xPlugin
  *
  * @return string
  */
 protected static function _pluginDirName($xPlugin)
 {
     $sPluginName = self::_pluginName($xPlugin);
     if (strpbrk($sPluginName, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')) {
         return F::StrUnderscore($sPluginName);
     }
     return $sPluginName;
 }
コード例 #3
0
ファイル: Entity.class.php プロジェクト: AntiqS/altocms
 /**
  * Ставим хук на вызов неизвестного метода и считаем что хотели вызвать метод какого либо модуля
  * Также производит обработку методов set* и get*
  * @see Engine::_CallModule
  *
  * @param string $sName Имя метода
  * @param array $aArgs Аргументы
  * @return mixed
  */
 public function __call($sName, $aArgs)
 {
     if (!strpos($sName, '_')) {
         $sType = strtolower(substr($sName, 0, 3));
         if ($sType == 'get' || $sType == 'set') {
             $sKey = F::StrUnderscore(substr($sName, 3));
             if ($sType == 'get') {
                 if ($this->isProp($sKey)) {
                     return $this->getProp($sKey);
                 } else {
                     if (preg_match('/Entity([^_]+)/', get_class($this), $aMatches)) {
                         $sModulePrefix = F::StrUnderscore($aMatches[1]) . '_';
                         if ($this->isProp($sModulePrefix . $sKey)) {
                             return $this->getProp($sModulePrefix . $sKey);
                         }
                     }
                 }
             } elseif ($sType == 'set' && (isset($aArgs[0]) || array_key_exists(0, $aArgs))) {
                 $this->setProp($sKey, $aArgs[0]);
             }
             return null;
         } else {
             return parent::__call($sName, $aArgs);
         }
     }
     return E::getInstance()->_CallModule($sName, $aArgs);
 }
コード例 #4
0
ファイル: function.php プロジェクト: AntiqS/altocms
function func_underscore($sStr)
{
    return F::StrUnderscore($sStr);
}
コード例 #5
0
ファイル: MapperORM.class.php プロジェクト: AntiqS/altocms
 /**
  * Возвращает имя таблицы для сущности
  *
  * @param EntityORM $oEntity    Объект сущности
  *
  * @return string
  */
 public static function GetTableName($oEntity)
 {
     /**
      * Варианты таблиц:
      *    prefix_user -> если модуль совпадает с сущностью
      *    prefix_user_invite -> если модуль не сопадает с сущностью
      */
     $sClass = E::getInstance()->Plugin_GetDelegater('entity', is_object($oEntity) ? get_class($oEntity) : $oEntity);
     $sModuleName = F::StrUnderscore(E::GetModuleName($sClass));
     $sEntityName = F::StrUnderscore(E::GetEntityName($sClass));
     if (strpos($sEntityName, $sModuleName) === 0) {
         $sTable = F::StrUnderscore($sEntityName);
     } else {
         $sTable = F::StrUnderscore($sModuleName) . '_' . F::StrUnderscore($sEntityName);
     }
     /**
      * Если название таблиц переопределено в конфиге, то возвращаем его
      */
     if (Config::Get('db.table.' . $sTable)) {
         return Config::Get('db.table.' . $sTable);
     } else {
         return Config::Get('db.table.prefix') . $sTable;
     }
 }
コード例 #6
0
ファイル: ModuleORM.class.php プロジェクト: AntiqS/altocms
 /**
  * Ставим хук на вызов неизвестного метода и считаем что хотели вызвать метод какого либо модуля.
  * Также обрабатывает различные ORM методы сущности, например
  * <pre>
  * $oUser->Save();
  * $oUser->Delete();
  * </pre>
  * И методы модуля ORM, например
  * <pre>
  *    E::ModuleUser()->GetUserItemsByName('Claus');
  *    E::ModuleUser()->GetUserItemsAll();
  * </pre>
  *
  * @see Engine::_CallModule
  *
  * @param string $sName Имя метода
  * @param array  $aArgs Аргументы
  *
  * @return mixed
  */
 public function __call($sName, $aArgs)
 {
     if (preg_match("@^add([\\w]+)\$@i", $sName, $aMatch)) {
         return $this->_AddEntity($aArgs[0]);
     }
     if (preg_match("@^update([\\w]+)\$@i", $sName, $aMatch)) {
         return $this->_UpdateEntity($aArgs[0]);
     }
     if (preg_match("@^save([\\w]+)\$@i", $sName, $aMatch)) {
         return $this->_SaveEntity($aArgs[0]);
     }
     if (preg_match("@^delete([\\w]+)\$@i", $sName, $aMatch)) {
         return $this->_DeleteEntity($aArgs[0]);
     }
     if (preg_match("@^reload([\\w]+)\$@i", $sName, $aMatch)) {
         return $this->_ReloadEntity($aArgs[0]);
     }
     if (preg_match("@^showcolumnsfrom([\\w]+)\$@i", $sName, $aMatch)) {
         return $this->_ShowColumnsFrom($aArgs[0]);
     }
     if (preg_match("@^showprimaryindexfrom([\\w]+)\$@i", $sName, $aMatch)) {
         return $this->_ShowPrimaryIndexFrom($aArgs[0]);
     }
     if (preg_match("@^getchildrenof([\\w]+)\$@i", $sName, $aMatch)) {
         return $this->_GetChildrenOfEntity($aArgs[0]);
     }
     if (preg_match("@^getparentof([\\w]+)\$@i", $sName, $aMatch)) {
         return $this->_GetParentOfEntity($aArgs[0]);
     }
     if (preg_match("@^getdescendantsof([\\w]+)\$@i", $sName, $aMatch)) {
         return $this->_GetDescendantsOfEntity($aArgs[0]);
     }
     if (preg_match("@^getancestorsof([\\w]+)\$@i", $sName, $aMatch)) {
         return $this->_GetAncestorsOfEntity($aArgs[0]);
     }
     if (preg_match("@^loadtreeof([\\w]+)\$@i", $sName, $aMatch)) {
         $sEntityFull = array_key_exists(1, $aMatch) ? $aMatch[1] : null;
         return $this->LoadTree($aArgs[0], $sEntityFull);
     }
     $sNameUnderscore = F::StrUnderscore($sName);
     $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 = F::StrUnderscore(E::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 = F::StrCamelize($sEntityName);
     /**
      * 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);
         }
     }
     /**
      * 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);
     }
     /**
      * getUserItemsByJoinTable() get_user_items_by_join_table
      */
     if (preg_match("@^get_([a-z]+)_items_by_join_table\$@i", $sNameUnderscore, $aMatch)) {
         return $this->GetItemsByJoinTable($aArgs[0], F::StrCamelize($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]) && is_array($aArgs[0])) {
             $aFilter = $aArgs[0];
         }
         return $this->GetItemsByFilter($aFilter, $sEntityName);
     }
     return $this->oEngine->_CallModule($sName, $aArgs);
 }
コード例 #7
0
ファイル: EntityORM.class.php プロジェクト: AntiqS/altocms
 /**
  * Используется для доступа к связанным данным типа MANY_TO_MANY
  *
  * @param string $sName    Название свойства к которому обращаемсяя
  *
  * @return mixed
  */
 public function __get($sName)
 {
     // Обработка обращений к обёрткам связей MANY_TO_MANY
     // Если связь загружена, возвращаем объект связи
     if (isset($this->_aManyToManyRelations[F::StrUnderscore($sName)])) {
         return $this->_aManyToManyRelations[F::StrUnderscore($sName)];
         // Есл не загружена, но связь с таким именем существет, пробуем загрузить и вернуть объект связи
     } elseif (isset($this->aRelations[F::StrUnderscore($sName)]) && $this->aRelations[F::StrUnderscore($sName)][0] == self::RELATION_TYPE_MANY_TO_MANY) {
         $sMethod = 'get' . F::StrCamelize($sName);
         $this->__call($sMethod, array());
         if (isset($this->_aManyToManyRelations[F::StrUnderscore($sName)])) {
             return $this->_aManyToManyRelations[F::StrUnderscore($sName)];
         }
         // В противном случае возвращаем то, что просили у объекта
     } else {
         return $this->{$sName};
     }
 }