mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-21 15:45:36 +08:00
update to build 417
This commit is contained in:
@@ -4,9 +4,11 @@
|
||||
namespace ZM\Utils\Manager;
|
||||
|
||||
|
||||
use ZM\Config\ZMConfig;
|
||||
use ZM\Console\Console;
|
||||
use ZM\Exception\ModulePackException;
|
||||
use ZM\Exception\ZMException;
|
||||
use ZM\Exception\ZMKnownException;
|
||||
use ZM\Module\ModulePacker;
|
||||
use ZM\Module\ModuleUnpacker;
|
||||
use ZM\Utils\DataProvider;
|
||||
@@ -36,12 +38,12 @@ class ModuleManager
|
||||
if ($json === null) continue;
|
||||
if (!isset($json["name"])) continue;
|
||||
if ($pathinfo["dirname"] == ".") {
|
||||
throw new ZMException(zm_internal_errcode("E00052") . "在/src/目录下不可以直接标记为模块(zm.json),因为命名空间不能为根空间!");
|
||||
throw new ZMKnownException("E00052", "在/src/目录下不可以直接标记为模块(zm.json),因为命名空间不能为根空间!");
|
||||
}
|
||||
$json["module-path"] = realpath($dir . "/" . $pathinfo["dirname"]);
|
||||
$json["namespace"] = str_replace("/", "\\", $pathinfo["dirname"]);
|
||||
if (isset($modules[$json["name"]])) {
|
||||
throw new ZMException(zm_internal_errcode("E00053") . "重名模块:" . $json["name"]);
|
||||
throw new ZMKnownException("E00053", "重名模块:" . $json["name"]);
|
||||
}
|
||||
$modules[$json["name"]] = $json;
|
||||
}
|
||||
@@ -50,7 +52,7 @@ class ModuleManager
|
||||
}
|
||||
|
||||
public static function getPackedModules(): array {
|
||||
$dir = DataProvider::getDataFolder() . "modules";
|
||||
$dir = ZMConfig::get("global", "module_loader")["load_path"] ?? (ZM_DATA . "modules");
|
||||
$ls = DataProvider::scanDirFiles($dir, true, false);
|
||||
if ($ls === false) return [];
|
||||
$modules = [];
|
||||
@@ -88,7 +90,10 @@ class ModuleManager
|
||||
public static function packModule($module): bool {
|
||||
try {
|
||||
$packer = new ModulePacker($module);
|
||||
$packer->setOutputPath(DataProvider::getDataFolder() . "output");
|
||||
if (!is_dir(DataProvider::getDataFolder())) throw new ModulePackException(zm_internal_errcode("E00070") . "zm_data dir not found!");
|
||||
$path = realpath(DataProvider::getDataFolder() . "/output");
|
||||
if ($path === false) mkdir($path = DataProvider::getDataFolder() . "/output");
|
||||
$packer->setOutputPath($path);
|
||||
$packer->setOverride();
|
||||
$packer->pack();
|
||||
return true;
|
||||
@@ -107,7 +112,7 @@ class ModuleManager
|
||||
public static function unpackModule($module, array $options = []) {
|
||||
try {
|
||||
$packer = new ModuleUnpacker($module);
|
||||
return $packer->unpack((bool)$options["override-light-cache"], (bool)$options["override-zm-data"], (bool)$options["override-source"]);
|
||||
return $packer->unpack((bool)$options["overwrite-light-cache"], (bool)$options["overwrite-zm-data"], (bool)$options["overwrite-source"], (bool)$options["ignore-depends"]);
|
||||
} catch (ZMException $e) {
|
||||
Console::error($e->getMessage());
|
||||
return false;
|
||||
|
||||
@@ -11,6 +11,17 @@ use ZM\Framework;
|
||||
use ZM\Store\Lock\SpinLock;
|
||||
use ZM\Store\ZMAtomic;
|
||||
use ZM\Store\ZMBuf;
|
||||
use function file_get_contents;
|
||||
use function get_included_files;
|
||||
use function is_callable;
|
||||
use function is_string;
|
||||
use function json_decode;
|
||||
use function mb_substr;
|
||||
use function md5_file;
|
||||
use function pathinfo;
|
||||
use function server;
|
||||
use function str_replace;
|
||||
use function substr;
|
||||
|
||||
class ZMUtil
|
||||
{
|
||||
@@ -45,15 +56,15 @@ class ZMUtil
|
||||
* 在工作进程中返回可以通过reload重新加载的php文件列表
|
||||
* @return string[]|string[][]
|
||||
*/
|
||||
public static function getReloadableFiles() {
|
||||
return array_map(
|
||||
function ($x) {
|
||||
return str_replace(DataProvider::getSourceRootDir() . '/', '', $x);
|
||||
}, array_diff(
|
||||
get_included_files(),
|
||||
Framework::$loaded_files
|
||||
)
|
||||
);
|
||||
public static function getReloadableFiles(): array {
|
||||
$array_map = [];
|
||||
foreach (array_diff(
|
||||
get_included_files(),
|
||||
Framework::$loaded_files
|
||||
) as $key => $x) {
|
||||
$array_map[$key] = str_replace(DataProvider::getSourceRootDir() . '/', '', $x);
|
||||
}
|
||||
return $array_map;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -61,10 +72,10 @@ class ZMUtil
|
||||
* @param $dir
|
||||
* @param $base_namespace
|
||||
* @param null|mixed $rule
|
||||
* @param bool $return_kv
|
||||
* @param bool $return_path_value
|
||||
* @return String[]
|
||||
*/
|
||||
public static function getClassesPsr4($dir, $base_namespace, $rule = null, $return_kv = false) {
|
||||
public static function getClassesPsr4($dir, $base_namespace, $rule = null, $return_path_value = false): array {
|
||||
// 预先读取下composer的file列表
|
||||
$composer = json_decode(file_get_contents(DataProvider::getSourceRootDir() . '/composer.json'), true);
|
||||
$classes = [];
|
||||
@@ -72,7 +83,7 @@ class ZMUtil
|
||||
$files = DataProvider::scanDirFiles($dir, true, true);
|
||||
foreach ($files as $v) {
|
||||
$pathinfo = pathinfo($v);
|
||||
if ($pathinfo['extension'] == 'php') {
|
||||
if (($pathinfo['extension'] ?? '') == 'php') {
|
||||
if ($rule === null) { //规则未设置回调时候,使用默认的识别过滤规则
|
||||
if (substr(file_get_contents($dir . '/' . $v), 6, 6) == '#plain') continue;
|
||||
elseif (mb_substr($v, 0, 7) == 'global_' || mb_substr($v, 0, 7) == 'script_') continue;
|
||||
@@ -82,7 +93,7 @@ class ZMUtil
|
||||
} elseif (is_callable($rule) && !($rule($dir, $pathinfo))) continue;
|
||||
$dirname = $pathinfo['dirname'] == '.' ? '' : (str_replace('/', '\\', $pathinfo['dirname']) . '\\');
|
||||
$class_name = $base_namespace . '\\' . $dirname . $pathinfo['filename'];
|
||||
if ($return_kv) $classes[$class_name] = $v;
|
||||
if (is_string($return_path_value)) $classes[$class_name] = $return_path_value . "/" .$v;
|
||||
else $classes[] = $class_name;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user