16 public static function load($extNames)
18 if (!is_array($extNames))
20 $extNames = [$extNames];
23 foreach ($extNames as $extName)
25 if (static::register($extName))
27 \CJSCore::init($extName);
36 public static function register($extName)
38 if (!is_string($extName))
43 if (\CJSCore::isExtRegistered($extName))
48 if (preg_match(
'/[^a-z0-9_.-]/i', $extName))
53 $extension = static::getConfig($extName);
54 if ($extension !==
null)
56 static::registerAssets($extName, $extension);
70 \CJSCore::registerExt($id,
$options);
78 foreach (
$path as $item)
80 $result[] = static::normalizeAssetPath($item, $extensionPath);
88 if (Path::isAbsolute(
$path))
93 return Path::combine($extensionPath,
$path);
108 if (!is_string($extName))
113 if (isset($cache[$extName]) || array_key_exists($extName, $cache))
115 return $cache[$extName];
118 $extensionPath = static::getPath($extName);
119 if ($extensionPath ===
null)
121 $cache[$extName] =
null;
126 if (!File::isFileExists($configFile))
128 $cache[$extName] =
null;
132 $config = include($configFile);
138 $config[
'js'] = static::normalizeAssetPath(
$config[
'js'], $extensionPath);
143 $config[
'css'] = static::normalizeAssetPath(
$config[
'css'], $extensionPath);
148 if (Directory::isDirectoryExists($langDirectory))
152 $config[
"lang"] = static::normalizeAssetPath(
$config[
"lang"], $extensionPath);
156 $config[
"lang"][] = $extensionPath .
"/config.php";
160 $config[
"lang"] = [
$config[
"lang"], $extensionPath .
"/config.php"];
165 $config[
"lang"] = $extensionPath .
"/config.php";
169 if (!isset(
$config[
'settings']) || !is_array(
$config[
'settings']))
177 return $cache[$extName];
187 $extensionPath = static::getPath($extName);
189 if ($extensionPath ===
null)
195 $configFile =
new File($configFilePath);
197 if (!$configFile->isExists())
203 $configContent = $configFile->getContents();
204 if (is_string($configContent) && !empty($configContent))
206 preg_match(
'/namespace:(?:\s+)?[\'"](.*)[\'"]/', $configContent,
$matches);
214 'namespace' => $namespace,
218 private static function getPath($extName)
222 if (!is_string($extName))
227 if (isset($cache[$extName]) || array_key_exists($extName, $cache))
229 return $cache[$extName];
232 $namespaces = explode(
".", $extName);
233 if (
count($namespaces) < 2)
235 $cache[$extName] =
null;
240 foreach ($namespaces as $namespace)
242 if (!preg_match(
"/^[a-z0-9_.\-]+$/i", $namespace))
244 $cache[$extName] =
null;
248 $path .=
"/" . $namespace;
255 return $cache[$extName];
264 $isRegistered = static::register($extName);
268 return \CJSCore::getHTML($extName);
280 $assets = [
'js' => [],
'css' => []];
282 if (is_array($extName))
284 foreach ($extName as
$name)
286 $currentAssets = static::getAssets(
$name);
287 $assets[
'js'] = array_merge($assets[
'js'], $currentAssets[
'js']);
288 $assets[
'css'] = array_merge($assets[
'css'], $currentAssets[
'css']);
294 if (is_string($extName))
296 $config = static::getConfig($extName);
305 $relAssets = static::getAssets(
$config[
'rel']);
306 $assets[
'js'] = array_merge($assets[
'js'], $relAssets[
'js']);
307 $assets[
'css'] = array_merge($assets[
'css'], $relAssets[
'css']);
314 $assets[
'js'] = array_merge($assets[
'js'],
$config[
'js']);
319 $assets[
'js'][] =
$config[
'js'];
327 $assets[
'css'] = array_merge($assets[
'css'],
$config[
'css']);
332 $assets[
'css'][] =
$config[
'css'];
336 if (isset(
$config[
'post_rel']))
338 $relAssets = static::getAssets(
$config[
'post_rel']);
339 $assets[
'js'] = array_merge($assets[
'js'], $relAssets[
'js']);
340 $assets[
'css'] = array_merge($assets[
'css'], $relAssets[
'css']);
344 $assets[
'js'] = array_unique($assets[
'js']);
345 $assets[
'css'] = array_unique($assets[
'css']);
356 return self::getDependencyListRecursive($extName);
366 $skipCoreJS = isset(
$option[
'skip_core_js']) &&
$option[
'skip_core_js'] ===
true;
367 $withDependency = !(isset(
$option[
'with_dependency']) &&
$option[
'with_dependency'] ===
false);
368 $skipExtensions =
$option[
'skip_extensions'] ?? [];
369 $getResolvedExtensionList = isset(
$option[
'get_resolved_extension_list']) &&
$option[
'get_resolved_extension_list'] ===
true;
373 $alreadyResolved = $skipExtensions;
376 $alreadyResolved[] =
'core';
380 $extNameList = is_array($extName) ? $extName : [$extName];
383 foreach ($extNameList as $extName)
385 if (in_array($extName, $alreadyResolved))
390 self::getDependencyListRecursive($extName,
true,
true, $extensions, $alreadyResolved);
395 foreach ($extNameList as $extName)
397 if (in_array($extName, $alreadyResolved))
403 $alreadyResolved[] = $extName;
410 foreach ($extensions as $index => $extension)
412 if (isset($extension[1][
'oninit']) && is_callable($extension[1][
'oninit']))
414 $callbackResult = call_user_func_array(
415 $extension[1][
'oninit'],
419 if (is_array($callbackResult))
421 foreach ($callbackResult as
$option => $value)
423 if (!is_array($value))
428 if (!isset($extension[1][
$option]))
437 $extensions[$index][1][
$option] = array_merge($extension[1][
$option], $value);
441 unset($extensions[$index][1][
'oninit']);
449 'lang_additional' => [],
455 if ($getResolvedExtensionList)
457 $result[
'resolved_extension'] = array_diff($alreadyResolved, $skipExtensions);
461 foreach ($extensions as $extension)
463 $extensionName = $extension[0];
500 private static function getDependencyListRecursive(
$name, $storeConfig =
false, $storeSelf =
false, &$resultList = [], &$alreadyResolved = [])
505 $namespaces = explode(
".",
$name);
506 if (
count($namespaces) == 1)
508 $config = self::getCoreConfigForDependencyList(
$name, $storeConfig, $resultList, $alreadyResolved);
512 $alreadyResolved[] =
$name;
517 $alreadyResolved[] =
$name;
522 foreach (
$config[
'rel'] as $dependencyName)
524 if (!in_array($dependencyName, $alreadyResolved))
526 self::getDependencyListRecursive($dependencyName, $storeConfig,
true, $resultList, $alreadyResolved);
539 $resultList[] =
$name;
545 foreach (
$config[
'post_rel'] as $dependencyName)
547 if (!in_array($dependencyName, $alreadyResolved))
549 self::getDependencyListRecursive($dependencyName, $storeConfig,
true, $resultList, $alreadyResolved);
560 foreach ($resultList as $element)
562 $uniqueArray[$element[0]] = $element;
564 $resultList = array_values($uniqueArray);
568 $resultList = array_unique($resultList);
574 private static function getCoreConfigForDependencyList(
$name, $storeConfig =
false, &$resultList = [], &$alreadyResolved = [])
576 $alreadyResolved[] =
$name;
581 if (!
$config[
'skip_core'] && !in_array(
'core', $alreadyResolved))
583 $coreConfig = \CJSCore::GetCoreConfig();
586 array_unshift($resultList, [
'core', $coreConfig]);
590 array_unshift($resultList,
'core');
593 $alreadyResolved[] =
'core';
static registerAssets($id, array $options)
static getDependencyList($extName)
static getAssets($extName)
static getBundleConfig($extName)
static normalizeAssetPath($path, $extensionPath)
static getConfig($extName)
static getResourceList($extName, $option=[])
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)