mirror of
https://github.com/zhamao-robot/zhamao-framework.git
synced 2026-07-25 17:45:34 +08:00
change autoload to hotload for phar hotload mode (build 442)
This commit is contained in:
@@ -28,7 +28,7 @@ use ZM\Exception\InitException;
|
|||||||
|
|
||||||
class ConsoleApplication extends Application
|
class ConsoleApplication extends Application
|
||||||
{
|
{
|
||||||
public const VERSION_ID = 441;
|
public const VERSION_ID = 442;
|
||||||
|
|
||||||
public const VERSION = '2.7.0-beta4';
|
public const VERSION = '2.7.0-beta4';
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ use ZM\Utils\ZMUtil;
|
|||||||
*/
|
*/
|
||||||
class ModulePacker
|
class ModulePacker
|
||||||
{
|
{
|
||||||
public const ZM_MODULE_PACKER_VERSION = '1.0';
|
public const ZM_MODULE_PACKER_VERSION = '1.1';
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
private $module = [];
|
private $module = [];
|
||||||
@@ -114,11 +114,11 @@ class ModulePacker
|
|||||||
$this->phar->startBuffering();
|
$this->phar->startBuffering();
|
||||||
Console::info('模块输出文件:' . $this->filename);
|
Console::info('模块输出文件:' . $this->filename);
|
||||||
|
|
||||||
$this->addFiles(); //添加文件
|
$this->addFiles(); // 添加文件
|
||||||
$this->addLightCacheStore(); //保存light-cache-store指定的项
|
$this->addLightCacheStore(); // 保存light-cache-store指定的项
|
||||||
$this->addModuleConfig(); //生成module-config.json
|
$this->addModuleConfig(); // 生成module-config.json
|
||||||
$this->addZMDataFiles(); //添加需要保存的zm_data下的目录或文件
|
$this->addZMDataFiles(); // 添加需要保存的zm_data下的目录或文件
|
||||||
$this->addEntry(); //生成模块的入口文件module_entry.php
|
$this->addEntry(); // 生成模块的入口文件module_entry.php
|
||||||
|
|
||||||
$this->phar->stopBuffering();
|
$this->phar->stopBuffering();
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ class ModulePacker
|
|||||||
if ($pos === 0) {
|
if ($pos === 0) {
|
||||||
$path_value = substr($this->module['module-path'], strlen(DataProvider::getSourceRootDir() . '/'));
|
$path_value = substr($this->module['module-path'], strlen(DataProvider::getSourceRootDir() . '/'));
|
||||||
} else {
|
} else {
|
||||||
throw new ModulePackException(zm_internal_errcode('E99999')); //未定义的错误
|
throw new ModulePackException(zm_internal_errcode('E99999')); // 未定义的错误
|
||||||
}
|
}
|
||||||
return ZMUtil::getClassesPsr4($this->module['module-path'], $this->module['namespace'], null, $path_value);
|
return ZMUtil::getClassesPsr4($this->module['module-path'], $this->module['namespace'], null, $path_value);
|
||||||
}
|
}
|
||||||
@@ -158,7 +158,7 @@ class ModulePacker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
foreach (($composer['autoload']['files'] ?? []) as $v) {
|
foreach (($composer['autoload']['files'] ?? []) as $v) {
|
||||||
if (strcmp($path, $v) === 0) {
|
if (strpos($v, $path) === 0) {
|
||||||
$item['files'][] = $v;
|
$item['files'][] = $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,9 +174,9 @@ class ModulePacker
|
|||||||
if (isset($this->module['light-cache-store'])) {
|
if (isset($this->module['light-cache-store'])) {
|
||||||
$store = [];
|
$store = [];
|
||||||
$r = ZMConfig::get('global', 'light_cache') ?? [
|
$r = ZMConfig::get('global', 'light_cache') ?? [
|
||||||
'size' => 512, //最多允许储存的条数(需要2的倍数)
|
'size' => 512, // 最多允许储存的条数(需要2的倍数)
|
||||||
'max_strlen' => 32768, //单行字符串最大长度(需要2的倍数)
|
'max_strlen' => 32768, // 单行字符串最大长度(需要2的倍数)
|
||||||
'hash_conflict_proportion' => 0.6, //Hash冲突率(越大越好,但是需要的内存更多)
|
'hash_conflict_proportion' => 0.6, // Hash冲突率(越大越好,但是需要的内存更多)
|
||||||
'persistence_path' => DataProvider::getDataFolder() . '_cache.json',
|
'persistence_path' => DataProvider::getDataFolder() . '_cache.json',
|
||||||
'auto_save_interval' => 900,
|
'auto_save_interval' => 900,
|
||||||
];
|
];
|
||||||
@@ -202,7 +202,7 @@ class ModulePacker
|
|||||||
'module-packer-version' => self::ZM_MODULE_PACKER_VERSION,
|
'module-packer-version' => self::ZM_MODULE_PACKER_VERSION,
|
||||||
'module-root-path' => $this->getRelativePath($this->module['module-path']),
|
'module-root-path' => $this->getRelativePath($this->module['module-path']),
|
||||||
'namespace' => $this->module['namespace'],
|
'namespace' => $this->module['namespace'],
|
||||||
'autoload-psr-4' => $this->generatePharAutoload(),
|
'hotload-psr-4' => $this->generatePharAutoload(),
|
||||||
'unpack' => [
|
'unpack' => [
|
||||||
'composer-autoload-items' => $this->getComposerAutoloadItems(),
|
'composer-autoload-items' => $this->getComposerAutoloadItems(),
|
||||||
'global-config-override' => $this->module['global-config-override'] ?? false,
|
'global-config-override' => $this->module['global-config-override'] ?? false,
|
||||||
@@ -210,6 +210,9 @@ class ModulePacker
|
|||||||
'allow-hotload' => $this->module['allow-hotload'] ?? false,
|
'allow-hotload' => $this->module['allow-hotload'] ?? false,
|
||||||
'pack-time' => time(),
|
'pack-time' => time(),
|
||||||
];
|
];
|
||||||
|
if (isset($stub_values['unpack']['composer-autoload-items']['files'])) {
|
||||||
|
$stub_values['hotload-files'] = $stub_values['unpack']['composer-autoload-items']['files'];
|
||||||
|
}
|
||||||
$this->phar->addFromString('zmplugin.json', json_encode($stub_values, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
$this->phar->addFromString('zmplugin.json', json_encode($stub_values, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
|
||||||
$this->module_config = $stub_values;
|
$this->module_config = $stub_values;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,9 +172,9 @@ class ModuleUnpacker
|
|||||||
private function copyLightCacheStore($override)
|
private function copyLightCacheStore($override)
|
||||||
{
|
{
|
||||||
$r = ZMConfig::get('global', 'light_cache') ?? [
|
$r = ZMConfig::get('global', 'light_cache') ?? [
|
||||||
'size' => 512, //最多允许储存的条数(需要2的倍数)
|
'size' => 512, // 最多允许储存的条数(需要2的倍数)
|
||||||
'max_strlen' => 32768, //单行字符串最大长度(需要2的倍数)
|
'max_strlen' => 32768, // 单行字符串最大长度(需要2的倍数)
|
||||||
'hash_conflict_proportion' => 0.6, //Hash冲突率(越大越好,但是需要的内存更多)
|
'hash_conflict_proportion' => 0.6, // Hash冲突率(越大越好,但是需要的内存更多)
|
||||||
'persistence_path' => DataProvider::getDataFolder() . '_cache.json',
|
'persistence_path' => DataProvider::getDataFolder() . '_cache.json',
|
||||||
'auto_save_interval' => 900,
|
'auto_save_interval' => 900,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -5,7 +5,10 @@ declare(strict_types=1);
|
|||||||
function loader__generated_id__()
|
function loader__generated_id__()
|
||||||
{
|
{
|
||||||
$obj = json_decode(file_get_contents(__DIR__ . '/zmplugin.json'), true);
|
$obj = json_decode(file_get_contents(__DIR__ . '/zmplugin.json'), true);
|
||||||
foreach (($obj['autoload-psr-4'] ?? []) as $v) {
|
foreach (($obj['hotload-psr-4'] ?? []) as $v) {
|
||||||
|
require_once Phar::running() . '/' . $v;
|
||||||
|
}
|
||||||
|
foreach (($obj['hotload-files'] ?? []) as $v) {
|
||||||
require_once Phar::running() . '/' . $v;
|
require_once Phar::running() . '/' . $v;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user