|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace tonisormisson\browsercomposer; |
|
4
|
|
|
|
|
5
|
|
|
use Composer\Console\Application; |
|
6
|
|
|
use Composer\Util\Filesystem; |
|
7
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
class BrowserComposer |
|
10
|
|
|
{ |
|
11
|
|
|
/** @var HtmlOutput */ |
|
12
|
|
|
public $output; |
|
13
|
|
|
|
|
14
|
|
|
/** @var string */ |
|
15
|
|
|
public $composerPath; |
|
16
|
|
|
|
|
17
|
|
|
/** @var boolean */ |
|
18
|
|
|
public $doInstall = false; |
|
19
|
|
|
|
|
20
|
|
|
/** @var boolean */ |
|
21
|
|
|
public $dryRun = false; |
|
22
|
|
|
|
|
23
|
|
|
/** @var boolean */ |
|
24
|
|
|
public $deleteCurrent = false; |
|
25
|
|
|
|
|
26
|
|
|
public function __construct() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->composerPath = __DIR__ . '/../'; |
|
29
|
|
|
$this->installComposer(); |
|
30
|
|
|
require_once __DIR__ . DIRECTORY_SEPARATOR . 'HtmlOutput.php'; |
|
31
|
|
|
$this->output = new HtmlOutput(); |
|
32
|
|
|
putenv('COMPOSER_HOME=' . __DIR__ . '/vendor/bin/composer'); |
|
33
|
|
|
// Improve performance when the xdebug extension is enabled |
|
34
|
|
|
//putenv('COMPOSER_DISABLE_XDEBUG_WARN=1'); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function run() { |
|
38
|
|
|
if ($this->deleteCurrent) { |
|
39
|
|
|
$this->deleteCurrentDependencies(); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
if ($this->doInstall) { |
|
43
|
|
|
$this->runComposer(); |
|
44
|
|
|
}else { |
|
45
|
|
|
$this->output->writeln('$'); |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
private function deleteCurrentDependencies() { |
|
50
|
|
|
|
|
51
|
|
|
try { |
|
52
|
|
|
$this->output->writeln('$ rm -rf vendor/*'); |
|
53
|
|
|
exec('rm -rf ../vendor/*'); |
|
54
|
|
|
} catch (\Exception $ex) { |
|
55
|
|
|
$this->output->writeln($ex->getMessage()); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
private function runComposer() { |
|
60
|
|
|
|
|
61
|
|
|
$this->output->writeln('$ composer install'); |
|
62
|
|
|
|
|
63
|
|
|
try { |
|
64
|
|
|
$params = array( |
|
65
|
|
|
'command' => 'install', |
|
66
|
|
|
'--no-dev' => true, |
|
67
|
|
|
'--optimize-autoloader' => true, |
|
68
|
|
|
'--no-suggest' => true, |
|
69
|
|
|
'--no-interaction' => true, |
|
70
|
|
|
'--no-progress' => true, |
|
71
|
|
|
'--working-dir'=>$this->composerPath, |
|
72
|
|
|
'--dry-run'=>$this->dryRun, |
|
73
|
|
|
//'--verbose' => true |
|
74
|
|
|
); |
|
75
|
|
|
$input = new ArrayInput($params); |
|
76
|
|
|
$application = new Application(); |
|
77
|
|
|
$application->setAutoExit(false); |
|
78
|
|
|
$application->run($input, $this->output); |
|
79
|
|
|
} catch (\Exception $ex) { |
|
80
|
|
|
$this->output->writeln($ex->getMessage()); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
$this->output->writeln("Done."); |
|
84
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
|
|
87
|
|
|
private function installComposer() { |
|
88
|
|
|
$composerPhar = $this->composerPath . '/composer.phar'; |
|
89
|
|
|
if (!file_exists($composerPhar)) { |
|
90
|
|
|
$data = file_get_contents('https://getcomposer.org/composer.phar'); |
|
91
|
|
|
echo $composerPhar; |
|
92
|
|
|
file_put_contents($composerPhar, $data); |
|
93
|
|
|
unset($data); |
|
94
|
|
|
} |
|
95
|
|
|
require_once 'phar://' . str_replace('\\', '/', $this->composerPath) . '/composer.phar/src/bootstrap.php'; |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
} |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths