change autoload to hotload for phar hotload mode (build 442)

This commit is contained in:
crazywhalecc
2022-03-20 16:20:14 +08:00
parent 78f78c607d
commit 444a77933a
4 changed files with 23 additions and 17 deletions

View File

@@ -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';

View File

@@ -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 = [];
@@ -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;
} }
} }
@@ -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;
} }

View File

@@ -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;
} }
} }