-
-
Notifications
You must be signed in to change notification settings - Fork 179
/
RequireCommand.php
70 lines (57 loc) · 2.32 KB
/
RequireCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Flex\Command;
use Composer\Command\RequireCommand as BaseRequireCommand;
use Composer\Package\Version\VersionParser;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Flex\PackageResolver;
use Symfony\Flex\Unpack\Operation;
use Symfony\Flex\Unpacker;
class RequireCommand extends BaseRequireCommand
{
private $resolver;
public function __construct(PackageResolver $resolver)
{
$this->resolver = $resolver;
parent::__construct();
}
protected function configure()
{
parent::configure();
$this->addOption('unpack', null, InputOption::VALUE_NONE, 'Unpack Symfony packs in composer.json.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$packages = $this->resolver->resolve($input->getArgument('packages'), true);
if ($packages) {
$versionParser = new VersionParser();
$op = new Operation($input->getOption('unpack'), $input->getOption('sort-packages') || $this->getComposer()->getConfig()->get('sort-packages'));
foreach ($versionParser->parseNameVersionPairs($packages) as $package) {
$op->addPackage($package['name'], $package['version'] ?? '', $input->getOption('dev'));
}
$unpacker = new Unpacker($this->getComposer(), $this->resolver);
$result = $unpacker->unpack($op);
$io = $this->getIO();
foreach ($result->getUnpacked() as $pkg) {
$io->writeError(sprintf('<info>Unpacked %s dependencies</>', $pkg->getName()));
}
$input->setArgument('packages', $result->getRequired());
} elseif ($input->getOption('unpack')) {
$this->getIO()->writeError('<error>--unpack is incompatible with the interactive mode.</>');
return 1;
}
if ($input->hasOption('no-suggest')) {
$input->setOption('no-suggest', true);
}
return parent::execute($input, $output);
}
}