mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-20 23:35:37 +08:00
Compare commits
7 Commits
71d803d36f
...
d16f5a972c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d16f5a972c | ||
|
|
ee46c1c387 | ||
|
|
64fde5fd8c | ||
|
|
dc5bf6dc98 | ||
|
|
20892ab194 | ||
|
|
e9d3f7e7eb | ||
|
|
2f8570b59e |
@@ -67,13 +67,11 @@ class SwitchPhpVersionCommand extends BaseCommand
|
||||
InteractiveTerm::finish('Removed: ' . $source_dir);
|
||||
}
|
||||
|
||||
// Set the PHP version for download
|
||||
// This defines the version that will be used when resolving php-src artifact
|
||||
define('SPC_BUILD_PHP_VERSION', $php_ver);
|
||||
|
||||
// Download new PHP source
|
||||
$this->output->writeln("<info>Downloading PHP {$php_ver} source...</info>");
|
||||
|
||||
$this->input->setOption('with-php', $php_ver);
|
||||
|
||||
$downloaderOptions = DownloaderOptions::extractFromConsoleOptions($this->input->getOptions());
|
||||
$downloader = new ArtifactDownloader($downloaderOptions);
|
||||
|
||||
|
||||
@@ -8,7 +8,12 @@ namespace StaticPHP\Attribute\Package;
|
||||
* Indicates that the annotated class defines a PHP extension.
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::IS_REPEATABLE)]
|
||||
readonly class Extension
|
||||
class Extension
|
||||
{
|
||||
public function __construct(public string $name) {}
|
||||
public function __construct(public string $name)
|
||||
{
|
||||
if (!str_starts_with($name, 'ext-')) {
|
||||
$this->name = "ext-{$name}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,7 +68,8 @@ class DownloadCommand extends BaseCommand
|
||||
}
|
||||
|
||||
// resolve package dependencies and get artifacts directly
|
||||
$resolved = DependencyResolver::resolve($packages, [], !$this->getOption('without-suggests'));
|
||||
$suggests = !($this->getOption('without-suggests') || $this->getOption('without-suggestions'));
|
||||
$resolved = DependencyResolver::resolve($packages, [], $suggests);
|
||||
foreach ($resolved as $pkg_name) {
|
||||
$pkg = PackageLoader::getPackage($pkg_name);
|
||||
if ($artifact = $pkg->getArtifact()) {
|
||||
|
||||
@@ -29,14 +29,14 @@ class ExtractCommand extends BaseCommand
|
||||
$this->addOption('for-libs', 'l', InputOption::VALUE_REQUIRED, 'Extract artifacts for libraries, e.g "libcares,openssl"');
|
||||
$this->addOption('for-packages', null, InputOption::VALUE_REQUIRED, 'Extract artifacts for packages, e.g "php,libssl,libcurl"');
|
||||
$this->addOption('without-suggests', null, null, 'Do not include suggested packages when using --for-extensions');
|
||||
$this->addOption('force-source', null, null, 'Force extract source even if binary is available');
|
||||
$this->addOption('source-only', null, null, 'Force extract source even if binary is available');
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
$cache = ApplicationContext::get(ArtifactCache::class);
|
||||
$extractor = new ArtifactExtractor($cache);
|
||||
$force_source = (bool) $this->getOption('force-source');
|
||||
$force_source = (bool) $this->getOption('source-only');
|
||||
|
||||
$artifacts = [];
|
||||
|
||||
@@ -59,6 +59,9 @@ class ExtractCommand extends BaseCommand
|
||||
$packages = array_map(fn ($x) => "ext-{$x}", parse_extension_list($exts));
|
||||
// Include php package when using for-extensions
|
||||
array_unshift($packages, 'php');
|
||||
array_unshift($packages, 'php-micro');
|
||||
array_unshift($packages, 'php-embed');
|
||||
array_unshift($packages, 'php-fpm');
|
||||
}
|
||||
if ($libs = $this->getOption('for-libs')) {
|
||||
$packages = array_merge($packages, parse_comma_list($libs));
|
||||
|
||||
@@ -8,19 +8,19 @@ use StaticPHP\DI\ApplicationContext;
|
||||
use StaticPHP\Package\PackageInstaller;
|
||||
use Symfony\Component\Console\Attribute\AsCommand;
|
||||
|
||||
#[AsCommand('install-pkg')]
|
||||
#[AsCommand('install-pkg', 'Install additional packages', ['i', 'install-package'])]
|
||||
class InstallPackageCommand extends BaseCommand
|
||||
{
|
||||
public function configure()
|
||||
{
|
||||
$this->addArgument('package', null, 'The package to install (name or path)');
|
||||
$this->addArgument('packages', null, 'The package to install (name or path)');
|
||||
}
|
||||
|
||||
public function handle(): int
|
||||
{
|
||||
ApplicationContext::set('elephant', true);
|
||||
$installer = new PackageInstaller([...$this->input->getOptions(), 'dl-prefer-binary' => true]);
|
||||
$installer->addInstallPackage($this->input->getArgument('package'));
|
||||
$installer->addInstallPackage($this->input->getArgument('packages'));
|
||||
$installer->run(true, true);
|
||||
return static::SUCCESS;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ class SPCConfigCommand extends BaseCommand
|
||||
{
|
||||
$this->addArgument('extensions', InputArgument::OPTIONAL, 'The extensions will be compiled, comma separated');
|
||||
$this->addOption('with-libs', null, InputOption::VALUE_REQUIRED, 'add additional libraries, comma separated', '');
|
||||
$this->addOption('with-packages', null, InputOption::VALUE_REQUIRED, 'add additional libraries, comma separated', '');
|
||||
$this->addOption('with-suggested-libs', 'L', null, 'Build with suggested libs for selected exts and libs');
|
||||
$this->addOption('with-suggests', null, null, 'Build with suggested packages for selected exts and libs');
|
||||
$this->addOption('with-suggested-exts', 'E', null, 'Build with suggested extensions for selected exts');
|
||||
@@ -31,15 +32,16 @@ class SPCConfigCommand extends BaseCommand
|
||||
public function handle(): int
|
||||
{
|
||||
// transform string to array
|
||||
$libraries = array_map('trim', array_filter(explode(',', $this->getOption('with-libs'))));
|
||||
$libraries = parse_comma_list($this->getOption('with-libs'));
|
||||
$libraries = array_merge($libraries, $this->getOption('with-packages'));
|
||||
// transform string to array
|
||||
$extensions = $this->getArgument('extensions') ? parse_extension_list($this->getArgument('extensions')) : [];
|
||||
$include_suggests = $this->getOption('with-suggests') ?: $this->getOption('with-suggested-libs') || $this->getOption('with-suggested-exts');
|
||||
|
||||
$util = new SPCConfigUtil(options: [
|
||||
'no_php' => $this->getOption('no-php'),
|
||||
'libs_only_deps' => $this->getOption('libs-only-deps'),
|
||||
'absolute_libs' => $this->getOption('absolute-libs'),
|
||||
'no_php' => (bool) $this->getOption('no-php'),
|
||||
'libs_only_deps' => (bool) $this->getOption('libs-only-deps'),
|
||||
'absolute_libs' => (bool) $this->getOption('absolute-libs'),
|
||||
]);
|
||||
$packages = array_merge(array_map(fn ($x) => "ext-{$x}", $extensions), $libraries);
|
||||
$config = $util->config($packages, $include_suggests);
|
||||
|
||||
@@ -87,7 +87,11 @@ class Registry
|
||||
if (isset($data['package']['config']) && is_array($data['package']['config'])) {
|
||||
foreach ($data['package']['config'] as $path) {
|
||||
$path = self::fullpath($path, dirname($registry_file));
|
||||
PackageConfig::loadFromFile($path);
|
||||
if (is_file($path)) {
|
||||
PackageConfig::loadFromFile($path);
|
||||
} elseif (is_dir($path)) {
|
||||
PackageConfig::loadFromDir($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +99,11 @@ class Registry
|
||||
if (isset($data['artifact']['config']) && is_array($data['artifact']['config'])) {
|
||||
foreach ($data['artifact']['config'] as $path) {
|
||||
$path = self::fullpath($path, dirname($registry_file));
|
||||
ArtifactConfig::loadFromFile($path);
|
||||
if (is_file($path)) {
|
||||
ArtifactConfig::loadFromFile($path);
|
||||
} elseif (is_dir($path)) {
|
||||
ArtifactConfig::loadFromDir($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +240,7 @@ class Registry
|
||||
*/
|
||||
private static function requireClassFile(string $class, ?string $file_path, string $base_path, bool $auto_require): void
|
||||
{
|
||||
if (!$auto_require || class_exists($class, true)) {
|
||||
if (!$auto_require || class_exists($class)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user