/** * Преобразование класса в путь к файлу плагина * * @param array|string $xClass - либо имя класса (строка), либо описание класса (массив) * @return string */ protected function ClassToPath($xClass) { if (is_array($xClass)) { $aClassElements = $xClass; } else { $aClassElements = HelperPlugin::ClassNameExplode($xClass); } $sFilePath = Config::Get('path.root.server'); if (isset($aClassElements['Plugin'])) { // класс внутри плагина if (is_string($xClass) and false !== strpos($aClassElements['Plugin'], '_') or sizeof($aClassElements) > 1) { $sFilePath .= '/plugins/' . strtolower($aClassElements['Plugin']); } else { $sFilePath .= '/plugins/Plugin' . ucfirst(strtolower($aClassElements['Plugin'])) . '.class.php'; } } if (isset($aClassElements['Action'])) { $sFilePath .= '/classes/actions/Action' . $aClassElements['Action'] . '.class.php'; } elseif (isset($aClassElements['Block'])) { $sFilePath .= '/classes/blocks/Block' . $aClassElements['Block'] . '.class.php'; } elseif (isset($aClassElements['Hook'])) { $sFilePath .= '/classes/hooks/Hook' . $aClassElements['Hook'] . '.class.php'; } elseif (isset($aClassElements['Module'])) { $sFilePath .= '/classes/modules/' . strtolower($aClassElements['Module']); if (isset($aClassElements['Mapper'])) { $sFilePath .= '/mapper/' . $aClassElements['Mapper'] . '.mapper.class.php'; } elseif (isset($aClassElements['Entity'])) { $sFilePath .= '/entity/' . $aClassElements['Entity'] . '.entity.class.php'; } else { $sFilePath .= '/' . ucfirst($aClassElements['Module']) . '.class.php'; } } elseif (isset($aClassElements['Mapper'])) { if (!isset($aClassElements['Plugin'])) { $sFilePath .= '/classes/modules/' . strtolower($aClassElements['Mapper']) . '/mapper/' . ucfirst(strtolower($aClassElements['Mapper'])) . '.mapper.class.php'; } } if (DIRECTORY_SEPARATOR != '/') { $sFilePath = str_replace(DIRECTORY_SEPARATOR, '/', $sFilePath); } return $sFilePath; }
protected function ClassNameExplode($sClassName) { if (preg_match('/^Plugin(\\w+)_(\\w+)Entity_(\\w+)/', $sClassName, $match)) { $aClassElements['Plugin'] = $match[1]; $aClassElements['Module'] = $match[2]; $aClassElements['Entity'] = $match[3]; } else { $aClassElements = HelperPlugin::ClassNameExplode($sClassName); } return $aClassElements; }