|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* This file is part of the box project. |
|
7
|
|
|
* |
|
8
|
|
|
* (c) Kevin Herrera <[email protected]> |
|
9
|
|
|
* Théo Fidry <[email protected]> |
|
10
|
|
|
* |
|
11
|
|
|
* This source file is subject to the MIT license that is bundled |
|
12
|
|
|
* with this source code in the file LICENSE. |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
namespace KevinGH\Box\Composer; |
|
16
|
|
|
|
|
17
|
|
|
use Composer\Console\Application as ComposerApplication; |
|
18
|
|
|
use Humbug\PhpScoper\Autoload\ScoperAutoloadGenerator; |
|
19
|
|
|
use Humbug\PhpScoper\Configuration as PhpScoperConfiguration; |
|
20
|
|
|
use Symfony\Component\Console\Input\ArrayInput; |
|
21
|
|
|
use Symfony\Component\Console\Output\NullOutput; |
|
22
|
|
|
use function KevinGH\Box\FileSystem\dump_file; |
|
23
|
|
|
|
|
24
|
|
|
final class ComposerOrchestrator |
|
25
|
|
|
{ |
|
26
|
|
|
private function __construct() |
|
27
|
|
|
{ |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public static function dumpAutoload(?PhpScoperConfiguration $configuration): void |
|
31
|
|
|
{ |
|
32
|
|
|
// TODO: we are running Composer a first time to assign ComposerApplication#io. However it should be possible |
|
33
|
|
|
// to do without by patching Composer at the core to construct the application with a NullIO |
|
34
|
|
|
$composerApplication = new ComposerApplication(); |
|
35
|
|
|
$composerApplication->doRun(new ArrayInput(['--no-plugins' => null]), new NullOutput()); |
|
36
|
|
|
|
|
37
|
|
|
$composer = $composerApplication->getComposer(false, true); |
|
38
|
|
|
|
|
39
|
|
|
if (null === $composer) { |
|
40
|
|
|
return; // No autoload to dump |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$installationManager = $composer->getInstallationManager(); |
|
44
|
|
|
$localRepo = $composer->getRepositoryManager()->getLocalRepository(); |
|
45
|
|
|
$package = $composer->getPackage(); |
|
46
|
|
|
$config = $composer->getConfig(); |
|
47
|
|
|
|
|
48
|
|
|
$generator = $composer->getAutoloadGenerator(); |
|
49
|
|
|
$generator->setDevMode(false); |
|
50
|
|
|
$generator->setClassMapAuthoritative(true); |
|
51
|
|
|
|
|
52
|
|
|
if (null !== $configuration) { |
|
53
|
|
|
// TODO: make prefix configurable |
|
54
|
|
|
$autoload = (new ScoperAutoloadGenerator($configuration->getWhitelist()))->dump('_HumbugBox'); |
|
55
|
|
|
|
|
56
|
|
|
// TODO: handle custom vendor dir |
|
57
|
|
|
// TODO: expose the scoper autoload file name via a constant |
|
58
|
|
|
dump_file('vendor/scoper-autoload.php', $autoload); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
$generator->dump($config, $localRepo, $package, $installationManager, 'composer', true); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|