1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SLLH\ComposerVersionsCheck; |
4
|
|
|
|
5
|
|
|
use Composer\Command\DependsCommand; |
6
|
|
|
use Composer\Composer; |
7
|
|
|
use Composer\IO\ConsoleIO; |
8
|
|
|
use Composer\Package\PackageInterface; |
9
|
|
|
use Symfony\Component\Console\Helper\HelperSet; |
10
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
11
|
|
|
use Symfony\Component\Console\Input\StringInput; |
12
|
|
|
use Symfony\Component\Console\Output\BufferedOutput; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Depends command wrapper class to get needed output. |
17
|
|
|
* |
18
|
|
|
* @author Sullivan Senechal <[email protected]> |
19
|
|
|
*/ |
20
|
|
|
final class DependsCommandWrapper |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var OutputInterface |
24
|
|
|
*/ |
25
|
|
|
private $output; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var DependsCommand |
29
|
|
|
*/ |
30
|
|
|
private $dependsCommand; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @param Composer $composer |
34
|
|
|
* @param bool $decoratedOutput |
35
|
|
|
*/ |
36
|
|
|
public function __construct(Composer $composer, $decoratedOutput = false) |
37
|
|
|
{ |
38
|
|
|
$this->dependsCommand = new DependsCommand(); |
39
|
|
|
$this->dependsCommand->setComposer($composer); |
40
|
|
|
|
41
|
|
|
$this->output = new BufferedOutput(); |
42
|
|
|
$this->output->setDecorated($decoratedOutput); |
43
|
|
|
|
44
|
|
|
$this->dependsCommand->setIO(new ConsoleIO(new StringInput('depends'), $this->output, new HelperSet())); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param PackageInterface $package |
49
|
|
|
* |
50
|
|
|
* @return string[] The output, array of lines. |
51
|
|
|
*/ |
52
|
|
|
public function dependsOutput(PackageInterface $package) |
53
|
|
|
{ |
54
|
|
|
$input = new ArrayInput(array( |
55
|
|
|
'depends', |
56
|
|
|
'package' => $package->getPrettyName(), |
57
|
|
|
), $this->dependsCommand->getDefinition()); |
58
|
|
|
$input->setOption('link-type', array('require', 'require-dev')); |
|
|
|
|
59
|
|
|
$this->dependsCommand->run($input, $this->output); |
60
|
|
|
|
61
|
|
|
$stringOutput = $this->output->fetch(); |
|
|
|
|
62
|
|
|
if (false === strstr($stringOutput, 'There is no installed package depending on ')) { |
63
|
|
|
$output = explode(PHP_EOL, $stringOutput); |
64
|
|
|
$output = array_map(function ($line) { |
65
|
|
|
return ' '.$line; |
66
|
|
|
}, $output); |
67
|
|
|
|
68
|
|
|
return array_slice($output, 0, -1); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return array(); |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: