1
0
mirror of https://github.com/php/pie.git synced 2026-03-23 23:12:17 +01:00

435: separate definition of system dependencies into configurable class

This commit is contained in:
James Titcumb
2026-03-05 09:27:10 +00:00
parent 076fddf53e
commit e63b9c75ac
4 changed files with 51 additions and 26 deletions

View File

@@ -148,7 +148,7 @@ class PhpBinaryPathBasedPlatformRepository extends PlatformRepository
/**
* Instructions for PIE to install these libraries, if they are missing, should be added
* into {@see \Php\Pie\DependencyResolver\DependencyInstaller\PrescanSystemDependencies}
* into {@see \Php\Pie\DependencyResolver\DependencyInstaller\SystemDependenciesDefinition::default()}
*/
private function addLibrariesUsingPkgConfig(): void
{

View File

@@ -28,6 +28,7 @@ use Php\Pie\Command\ShowCommand;
use Php\Pie\Command\UninstallCommand;
use Php\Pie\ComposerIntegration\MinimalHelperSet;
use Php\Pie\ComposerIntegration\QuieterConsoleIO;
use Php\Pie\DependencyResolver\DependencyInstaller\SystemDependenciesDefinition;
use Php\Pie\DependencyResolver\DependencyResolver;
use Php\Pie\DependencyResolver\ResolveDependencyWithComposer;
use Php\Pie\Downloading\GithubPackageReleaseAssets;
@@ -217,6 +218,13 @@ final class Container
},
);
$container->singleton(
SystemDependenciesDefinition::class,
static function (): SystemDependenciesDefinition {
return SystemDependenciesDefinition::default();
},
);
return $container;
}

View File

@@ -27,33 +27,13 @@ use function str_replace;
/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
class PrescanSystemDependencies
{
/** @var array<non-empty-string, array<non-empty-string, non-empty-string>> */
private readonly array $libraries;
public function __construct(
private readonly DependencyResolver $dependencyResolver,
private readonly FetchDependencyStatuses $fetchDependencyStatuses,
private readonly IOInterface $io,
private readonly SystemDependenciesDefinition $systemDependenciesDefinition,
private readonly PackageManager|null $packageManager,
private readonly IOInterface $io,
) {
/**
* Checks for the existence of these libraries should be added into
* {@see \Php\Pie\ComposerIntegration\PhpBinaryPathBasedPlatformRepository::addLibrariesUsingPkgConfig()}
*/
$this->libraries = [
'sodium' => [
PackageManager::Apt->value => 'libsodium-dev',
PackageManager::Apk->value => 'libsodium-dev',
PackageManager::Dnf->value => 'pkgconfig(libsodium)',
PackageManager::Yum->value => 'pkgconfig(libsodium)',
],
'jpeg' => [
PackageManager::Apt->value => 'libjpeg-dev',
PackageManager::Apk->value => 'libjpeg-turbo-dev',
PackageManager::Dnf->value => 'pkgconfig(libjpeg)',
PackageManager::Yum->value => 'pkgconfig(libjpeg)',
],
];
}
public function __invoke(Composer $composer, TargetPlatform $targetPlatform, RequestedPackageAndVersion $requestedNameAndVersion): void
@@ -116,7 +96,7 @@ class PrescanSystemDependencies
{
$depName = str_replace('lib-', '', $unmetDependency->name);
if (! array_key_exists($depName, $this->libraries)) {
if (! array_key_exists($depName, $this->systemDependenciesDefinition->definition)) {
$this->io->writeError(
sprintf('Could not automatically install %s, as PIE does not have the package manager definition.', $unmetDependency->name),
verbosity: IOInterface::VERBOSE,
@@ -125,7 +105,7 @@ class PrescanSystemDependencies
return null;
}
if (! array_key_exists($packageManager->value, $this->libraries[$depName])) {
if (! array_key_exists($packageManager->value, $this->systemDependenciesDefinition->definition[$depName])) {
$this->io->writeError(
sprintf('Could not automatically install "%s", as PIE does not have a definition for "%s"', $unmetDependency->name, $packageManager->value),
verbosity: IOInterface::VERBOSE,
@@ -134,7 +114,7 @@ class PrescanSystemDependencies
return null;
}
$packageManagerPackage = $this->libraries[$depName][$packageManager->value];
$packageManagerPackage = $this->systemDependenciesDefinition->definition[$depName][$packageManager->value];
// Note: ideally, we should also parse the version constraint. This initial iteration will ignore that, to be improved later.
$this->io->write(

View File

@@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Php\Pie\DependencyResolver\DependencyInstaller;
use Php\Pie\Platform\PackageManager;
class SystemDependenciesDefinition
{
/** @param array<non-empty-string, array<non-empty-string, non-empty-string>> $definition */
public function __construct(public readonly array $definition)
{
}
/**
* Checks for the existence of these libraries should be added into
* {@see \Php\Pie\ComposerIntegration\PhpBinaryPathBasedPlatformRepository::addLibrariesUsingPkgConfig()}
*/
public static function default(): self
{
return new self([
'sodium' => [
PackageManager::Apt->value => 'libsodium-dev',
PackageManager::Apk->value => 'libsodium-dev',
PackageManager::Dnf->value => 'pkgconfig(libsodium)',
PackageManager::Yum->value => 'pkgconfig(libsodium)',
],
'jpeg' => [
PackageManager::Apt->value => 'libjpeg-dev',
PackageManager::Apk->value => 'libjpeg-turbo-dev',
PackageManager::Dnf->value => 'pkgconfig(libjpeg)',
PackageManager::Yum->value => 'pkgconfig(libjpeg)',
],
]);
}
}