diff --git a/phpstan.neon b/phpstan.neon index 25b6cecf..66ea6614 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -11,3 +11,4 @@ parameters: dynamicConstantNames: - SWOOLE_VERSION - ZM_TEST_LOG_DEBUG + - _PHAR_STUB_ID diff --git a/src/ZM/script_phar_stub.php b/src/ZM/script_phar_stub.php index d50e6a4f..3650b878 100644 --- a/src/ZM/script_phar_stub.php +++ b/src/ZM/script_phar_stub.php @@ -2,6 +2,8 @@ declare(strict_types=1); +const _PHAR_STUB_ID = '__generated_id__'; + function loader__generated_id__() { $obj = json_decode(file_get_contents(__DIR__ . '/zmplugin.json'), true); @@ -12,4 +14,8 @@ function loader__generated_id__() require_once Phar::running() . '/' . $v; } } +if ('__generate' . 'd_id__' === _PHAR_STUB_ID) { + echo 'Cannot execute this file directly!' . PHP_EOL; + exit(1); +} return json_decode(file_get_contents(__DIR__ . '/zmplugin.json'), true) ?? ['zm_module' => false];