diff --git a/bin/spc b/bin/spc index 58749f61..a8571b1b 100755 --- a/bin/spc +++ b/bin/spc @@ -4,7 +4,13 @@ use SPC\ConsoleApplication; use SPC\exception\ExceptionHandler; -require_once __DIR__ . '/../vendor/autoload.php'; +if (file_exists(dirname(__DIR__) . '/vendor/autoload.php')) { + // Current: ./bin (git/project mode) + require_once dirname(__DIR__) . '/vendor/autoload.php'; +} else { + // Current: ./vendor/crazywhalecc/static-php-cli/bin (composer library mode) + require_once dirname(__DIR__, 3) . '/autoload.php'; +} // 防止 Micro 打包状态下不支持中文的显示(虽然这个项目目前好像没输出过中文?) if (PHP_OS_FAMILY === 'Windows' && Phar::running()) { diff --git a/src/globals/defines.php b/src/globals/defines.php index 3415f5c6..79b85406 100644 --- a/src/globals/defines.php +++ b/src/globals/defines.php @@ -5,7 +5,7 @@ declare(strict_types=1); use ZM\Logger\ConsoleLogger; define('WORKING_DIR', getcwd()); -const ROOT_DIR = __DIR__ . '/../..'; +define('ROOT_DIR', dirname(__DIR__, 2)); // CLI start time define('START_TIME', microtime(true));