mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-09 01:45:36 +08:00
Add support for package environment variables and path injection
This commit is contained in:
@@ -40,6 +40,9 @@ class ConfigValidator
|
|||||||
'static-libs' => ConfigType::LIST_ARRAY, // @
|
'static-libs' => ConfigType::LIST_ARRAY, // @
|
||||||
'pkg-configs' => ConfigType::LIST_ARRAY,
|
'pkg-configs' => ConfigType::LIST_ARRAY,
|
||||||
'static-bins' => ConfigType::LIST_ARRAY, // @
|
'static-bins' => ConfigType::LIST_ARRAY, // @
|
||||||
|
'path' => ConfigType::LIST_ARRAY, // @
|
||||||
|
'env' => ConfigType::ASSOC_ARRAY, // @
|
||||||
|
'append-env' => ConfigType::ASSOC_ARRAY, // @
|
||||||
];
|
];
|
||||||
|
|
||||||
public const array PACKAGE_FIELDS = [
|
public const array PACKAGE_FIELDS = [
|
||||||
@@ -60,6 +63,9 @@ class ConfigValidator
|
|||||||
'static-libs' => false, // @
|
'static-libs' => false, // @
|
||||||
'pkg-configs' => false,
|
'pkg-configs' => false,
|
||||||
'static-bins' => false, // @
|
'static-bins' => false, // @
|
||||||
|
'path' => false, // @
|
||||||
|
'env' => false, // @
|
||||||
|
'append-env' => false, // @
|
||||||
];
|
];
|
||||||
|
|
||||||
public const array SUFFIX_ALLOWED_FIELDS = [
|
public const array SUFFIX_ALLOWED_FIELDS = [
|
||||||
@@ -68,6 +74,9 @@ class ConfigValidator
|
|||||||
'headers',
|
'headers',
|
||||||
'static-libs',
|
'static-libs',
|
||||||
'static-bins',
|
'static-bins',
|
||||||
|
'path',
|
||||||
|
'env',
|
||||||
|
'append-env',
|
||||||
];
|
];
|
||||||
|
|
||||||
public const array PHP_EXTENSION_FIELDS = [
|
public const array PHP_EXTENSION_FIELDS = [
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ use StaticPHP\Artifact\ArtifactCache;
|
|||||||
use StaticPHP\Artifact\ArtifactDownloader;
|
use StaticPHP\Artifact\ArtifactDownloader;
|
||||||
use StaticPHP\Artifact\ArtifactExtractor;
|
use StaticPHP\Artifact\ArtifactExtractor;
|
||||||
use StaticPHP\Artifact\DownloaderOptions;
|
use StaticPHP\Artifact\DownloaderOptions;
|
||||||
|
use StaticPHP\Config\PackageConfig;
|
||||||
use StaticPHP\DI\ApplicationContext;
|
use StaticPHP\DI\ApplicationContext;
|
||||||
use StaticPHP\Exception\WrongUsageException;
|
use StaticPHP\Exception\WrongUsageException;
|
||||||
use StaticPHP\Registry\PackageLoader;
|
use StaticPHP\Registry\PackageLoader;
|
||||||
@@ -580,6 +581,30 @@ class PackageInstaller
|
|||||||
foreach ($resolved_packages as $pkg_name) {
|
foreach ($resolved_packages as $pkg_name) {
|
||||||
$this->packages[$pkg_name] = PackageLoader::getPackage($pkg_name);
|
$this->packages[$pkg_name] = PackageLoader::getPackage($pkg_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
foreach ($this->packages as $package) {
|
||||||
|
$this->injectPackageEnvs($package);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function injectPackageEnvs(Package $package): void
|
||||||
|
{
|
||||||
|
$name = $package->getName();
|
||||||
|
|
||||||
|
$paths = PackageConfig::get($name, 'path', []);
|
||||||
|
foreach ($paths as $path) {
|
||||||
|
GlobalEnvManager::addPathIfNotExists(FileSystem::replacePathVariable($path));
|
||||||
|
}
|
||||||
|
|
||||||
|
$envs = PackageConfig::get($name, 'env', []);
|
||||||
|
foreach ($envs as $k => $v) {
|
||||||
|
GlobalEnvManager::putenv("{$k}=" . FileSystem::replacePathVariable((string) $v));
|
||||||
|
}
|
||||||
|
|
||||||
|
$append_envs = PackageConfig::get($name, 'append-env', []);
|
||||||
|
foreach ($append_envs as $k => $v) {
|
||||||
|
GlobalEnvManager::appendEnv($k, FileSystem::replacePathVariable((string) $v));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private function handlePhpTargetPackage(TargetPackage $package): void
|
private function handlePhpTargetPackage(TargetPackage $package): void
|
||||||
|
|||||||
@@ -112,6 +112,17 @@ class GlobalEnvManager
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function appendEnv(string $key, string $value): void
|
||||||
|
{
|
||||||
|
$existing = getenv($key);
|
||||||
|
if ($existing !== false && $existing !== '') {
|
||||||
|
$separator = SystemTarget::isUnix() ? ':' : ';';
|
||||||
|
self::putenv("{$key}={$value}{$separator}{$existing}");
|
||||||
|
} else {
|
||||||
|
self::putenv("{$key}={$value}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the toolchain after the environment variables are set.
|
* Initialize the toolchain after the environment variables are set.
|
||||||
* The toolchain or environment availability check is done here.
|
* The toolchain or environment availability check is done here.
|
||||||
|
|||||||
Reference in New Issue
Block a user