mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-08 17:35:36 +08:00
Refactor exception handler to v3, use standard shell exitcode
This commit is contained in:
@@ -7,6 +7,7 @@ namespace StaticPHP\Package;
|
||||
use StaticPHP\Artifact\Artifact;
|
||||
use StaticPHP\Config\PackageConfig;
|
||||
use StaticPHP\DI\ApplicationContext;
|
||||
use StaticPHP\Exception\SPCException;
|
||||
use StaticPHP\Exception\SPCInternalException;
|
||||
use StaticPHP\Registry\ArtifactLoader;
|
||||
use StaticPHP\Registry\PackageLoader;
|
||||
@@ -63,13 +64,29 @@ abstract class Package
|
||||
static::class => $this,
|
||||
], $context);
|
||||
|
||||
// emit BeforeStage
|
||||
$this->emitBeforeStage($name, $stageContext);
|
||||
try {
|
||||
// emit BeforeStage
|
||||
$this->emitBeforeStage($name, $stageContext);
|
||||
|
||||
$ret = ApplicationContext::invoke($this->stages[$name], $stageContext);
|
||||
// emit AfterStage
|
||||
$this->emitAfterStage($name, $stageContext, $ret);
|
||||
return $ret;
|
||||
$ret = ApplicationContext::invoke($this->stages[$name], $stageContext);
|
||||
// emit AfterStage
|
||||
$this->emitAfterStage($name, $stageContext, $ret);
|
||||
return $ret;
|
||||
} catch (SPCException $e) {
|
||||
// Bind package information only if not already bound
|
||||
if ($e->getPackageInfo() === null) {
|
||||
$e->bindPackageInfo([
|
||||
'package_name' => $this->name,
|
||||
'package_type' => $this->type,
|
||||
'package_class' => static::class,
|
||||
'file' => null,
|
||||
'line' => null,
|
||||
]);
|
||||
}
|
||||
// Always add current stage to the stack to build call chain
|
||||
$e->addStageToStack($name, $stageContext);
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
public function setOutput(string $key, string $value): static
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace StaticPHP\Package;
|
||||
|
||||
use StaticPHP\Config\PackageConfig;
|
||||
use StaticPHP\DI\ApplicationContext;
|
||||
use StaticPHP\Exception\SPCException;
|
||||
use StaticPHP\Exception\SPCInternalException;
|
||||
use StaticPHP\Exception\WrongUsageException;
|
||||
use StaticPHP\Runtime\Shell\Shell;
|
||||
@@ -59,19 +60,33 @@ class PackageBuilder
|
||||
InteractiveTerm::advance();
|
||||
});
|
||||
|
||||
if ($package->getType() !== 'virtual-target') {
|
||||
// patch before build
|
||||
$package->emitPatchBeforeBuild();
|
||||
}
|
||||
|
||||
// build
|
||||
$package->runStage('build');
|
||||
|
||||
if ($package->getType() !== 'virtual-target') {
|
||||
// install license
|
||||
if (($license = PackageConfig::get($package->getName(), 'license')) !== null) {
|
||||
$this->installLicense($package, $license);
|
||||
try {
|
||||
if ($package->getType() !== 'virtual-target') {
|
||||
// patch before build
|
||||
$package->emitPatchBeforeBuild();
|
||||
}
|
||||
|
||||
// build
|
||||
$package->runStage('build');
|
||||
|
||||
if ($package->getType() !== 'virtual-target') {
|
||||
// install license
|
||||
if (($license = PackageConfig::get($package->getName(), 'license')) !== null) {
|
||||
$this->installLicense($package, $license);
|
||||
}
|
||||
}
|
||||
} catch (SPCException $e) {
|
||||
// Ensure package information is bound if not already
|
||||
if ($e->getPackageInfo() === null) {
|
||||
$e->bindPackageInfo([
|
||||
'package_name' => $package->name,
|
||||
'package_type' => $package->type,
|
||||
'package_class' => get_class($package),
|
||||
'file' => null,
|
||||
'line' => null,
|
||||
]);
|
||||
}
|
||||
throw $e;
|
||||
}
|
||||
return SPC_STATUS_BUILT;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user