8
8
use InvalidArgumentException ;
9
9
use Php \Pie \DependencyResolver \DependencyResolver ;
10
10
use Php \Pie \Downloading \DownloadAndExtract ;
11
+ use Php \Pie \TargetPhp \PhpBinaryPath ;
11
12
use Symfony \Component \Console \Attribute \AsCommand ;
12
13
use Symfony \Component \Console \Command \Command ;
13
14
use Symfony \Component \Console \Input \InputArgument ;
14
15
use Symfony \Component \Console \Input \InputInterface ;
16
+ use Symfony \Component \Console \Input \InputOption ;
15
17
use Symfony \Component \Console \Output \OutputInterface ;
16
18
use Webmozart \Assert \Assert ;
17
19
30
32
final class DownloadCommand extends Command
31
33
{
32
34
private const ARG_REQUESTED_PACKAGE_AND_VERSION = 'requested-package-and-version ' ;
35
+ private const OPTION_WITH_PHP_CONFIG = 'with-php-config ' ;
33
36
34
37
public function __construct (
35
38
private readonly DependencyResolver $ dependencyResolver ,
@@ -47,18 +50,35 @@ public function configure(): void
47
50
InputArgument::REQUIRED ,
48
51
'The extension name and version constraint to use, in the format {ext-name}{?:version-constraint}{?@dev-branch-name}, for example `ext-debug:^1.0` ' ,
49
52
);
53
+ $ this ->addOption (
54
+ self ::OPTION_WITH_PHP_CONFIG ,
55
+ null ,
56
+ InputOption::VALUE_OPTIONAL ,
57
+ 'The path to `php-config` to use ' ,
58
+ );
50
59
}
51
60
52
61
public function execute (InputInterface $ input , OutputInterface $ output ): int
53
62
{
63
+ $ phpBinaryPath = PhpBinaryPath::fromCurrentProcess ();
64
+
65
+ /** @var mixed $withPhpConfig */
66
+ $ withPhpConfig = $ input ->getOption (self ::OPTION_WITH_PHP_CONFIG );
67
+ if (is_string ($ withPhpConfig ) && $ withPhpConfig !== '' ) {
68
+ $ phpBinaryPath = PhpBinaryPath::fromPhpConfigExecutable ($ withPhpConfig );
69
+ }
70
+
71
+ $ output ->writeln (sprintf ('<info>You are running PHP %s</info> ' , PHP_VERSION ));
72
+ $ output ->writeln (sprintf ('<info>Target PHP installation: %s (from %s)</info> ' , $ phpBinaryPath ->version (), $ phpBinaryPath ->phpBinaryPath ));
73
+
54
74
$ requestedNameAndVersionPair = $ this ->requestedNameAndVersionPair ($ input );
55
75
56
76
$ package = ($ this ->dependencyResolver )(
77
+ $ phpBinaryPath ,
57
78
$ requestedNameAndVersionPair ['name ' ],
58
79
$ requestedNameAndVersionPair ['version ' ],
59
80
);
60
81
61
- $ output ->writeln (sprintf ('<info>You are running PHP %s</info> ' , PHP_VERSION ));
62
82
$ output ->writeln (sprintf ('<info>Found package:</info> %s (version: %s) ' , $ package ->name , $ package ->version ));
63
83
$ output ->writeln (sprintf ('<info>Dist download URL:</info> %s ' , $ package ->downloadUrl ?? '(none) ' ));
64
84
0 commit comments