/** * Ф-ия для добавления папки из которой черпать файлы плугинов. * @param String $pluginsPath - полный путь к папке с плугинами. * @param bool $directLoad = false - загрузить все файлы плугинов сразу, а не подгружать по мере вызова. * @return true Если папка есть. * @return false Если папки нет. */ public static function addPlugins($pluginsPath, $directLoad = false) { removeDirLastSlash($pluginsPath); $pluginsPath = DOC_ROOT . $pluginsPath; if (is_dir($pluginsPath)) { self::$pluginDirs[] = $pluginsPath; if ($directLoad) { $dirPlugins = opendir($pluginsPath); while ($elementOfDir = readdir($dirPlugins)) { if ($elementOfDir != ".." && $elementOfDir != "." && substr($elementOfDir, strlen($elementOfDir) - 4, strlen($elementOfDir)) == ".php" && substr($elementOfDir, 0, strlen(self::funcFilePrefix)) == self::funcFilePrefix) { $curLoadFuncName = substr($elementOfDir, strlen(self::funcFilePrefix), -4); if (!function_exists(self::funcNamePrefix . $curLoadFuncName)) { //d("dload fname: ".$curLoadFuncName); //d("dload $curLoadFuncName func in ".$pluginsPath."/".$elementOfDir); require_once $pluginsPath . "/" . $elementOfDir; } } } } return true; } else { return false; } }
public static function includeLibFiles($libDirPath, $argDirectLoadClasses = self::global_set, $debug = self::global_set) { if (!self::$bInit) { return false; } if ($debug === self::global_set) { $debug = self::$debugMe; } $dctLoadSetSrc = ""; if ($argDirectLoadClasses === self::global_set) { $argDirectLoadClasses = (bool) self::$directLoadClasses; $dctLoadSetSrc = "global set"; } else { $argDirectLoadClasses = (bool) $argDirectLoadClasses; $dctLoadSetSrc = "argument set"; } if ($debug) { echo "<b>CALL Modules::includeLibFiles({$libDirPath})</b><br />"; } removeDirLastSlash($libDirPath); $libDirPath = DOC_ROOT . '/' . $libDirPath; if (!is_dir($libDirPath)) { if ($debug) { echo "<b>Library directory is incorrect: " . $libDirPath . ")</b><br />"; } return false; } $dirLib = opendir($libDirPath); $arFilesList = array(); $arDLoad = array(); $arBLoad = array(); while ($elementOfDir = readdir($dirLib)) { if ($elementOfDir != ".." && $elementOfDir != "." && substr($elementOfDir, strlen($elementOfDir) - 4, strlen($elementOfDir)) == ".php") { $arFilesList[] = $elementOfDir; } } // Необходимо для регулирования порядка загрузки. sort($arFilesList); $newClassesPaths = array(); foreach ($arFilesList as $elementOfDir) { // Заполняем массив классов и файлов в которых они лежат if (substr($elementOfDir, 0, 6) == "class.") { $className = substr($elementOfDir, 6, -4); //echo "CLASS NAME: ".$className."<br />"; $regClassNumPrefix = "#^(([0-9]{1,2}\\.){1,2}){1}([a-zA-Z0-9]{2,}){1}\$#"; if (preg_match($regClassNumPrefix, $className, $arClassFileNameMatches)) { $className = $arClassFileNameMatches[3]; } $arClassName = explode("-", $className); if (count($arClassName) < 2) { $className = '\\' . __NAMESPACE__ . '\\' . $arClassName[0]; } else { $className = '\\'; foreach ($arClassName as $keyNameSpaceOrClass => &$nameSpaceOrClass) { $className .= ($keyNameSpaceOrClass == 0 ? "" : "\\") . $nameSpaceOrClass; } } if (!array_key_exists($className, self::$classesPaths)) { $newClassesPaths[$className] = $libDirPath . "/" . $elementOfDir; } } elseif (substr($elementOfDir, 0, 6) == "bload.") { $arBLoad[] = $libDirPath . "/" . $elementOfDir; } elseif (substr($elementOfDir, 0, 6) == "dload.") { $arDLoad[] = $libDirPath . "/" . $elementOfDir; } } if ($debug) { if (count($newClassesPaths) > 0) { echo "<b>Found new classes: </b>"; echo "<pre>"; print_r($newClassesPaths); echo "</pre>"; } else { echo "<b>New classes not found.</b><br />"; } } self::$classesPaths = array_merge_recursive(self::$classesPaths, $newClassesPaths); // Перед классами загружаем bload. if ($debug) { echo "Loadgin BLOAD files: <br />"; } foreach ($arBLoad as $filePathBLoad) { if ($debug) { echo "bload: {$filePathBLoad} <br />"; } require_once $filePathBLoad; } /** * Если установлена опция прямой загрузки, то загружамем все полученные файлы классов. * Важно было сначала наполнить пул имен классов, что бы не возникла ситуация когда * подключается файл в котором класс наследует другой класс, файл которого ещё не подключен. * Наполнив в первую очередь пул, мы обеспечили работу ф-ии self::autoloadClasses. * Так что в крайнем случае, сработает __autoload и догрузит необходимые классы из пула */ if ($argDirectLoadClasses) { if ($debug) { echo "DIRECT_LOAD_CLASSES==TRUE. Loading new CLASS files.<br />"; } foreach ($newClassesPaths as $className => $classFilePath) { if (!class_exists($className, false)) { if ($debug) { echo "load: {$className} - {$classFilePath} <br />"; } require_once $classFilePath; } elseif ($debug) { echo "load: {$className} - already included in {$classFilePath} <br />"; } } } // После классов загружаем dload. if ($debug) { echo "Loadgin DLOAD files: <br />"; } foreach ($arDLoad as $filePathDLoad) { if ($debug) { echo "dload: {$filePathDLoad} <br />"; } require_once $filePathDLoad; } return true; }