Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
Autoload | |
0.00% |
0 / 29 |
|
0.00% |
0 / 2 |
20 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
generate | |
0.00% |
0 / 25 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | /** |
3 | * Generate an `autoload.php` file in the root of the target directory. |
4 | * |
5 | * @see \Composer\Autoload\ClassMapGenerator |
6 | */ |
7 | |
8 | namespace BrianHenryIE\Strauss\Pipeline; |
9 | |
10 | use BrianHenryIE\Strauss\Composer\Extra\StraussConfig; |
11 | use BrianHenryIE\Strauss\Config\AutoloadConfigInterface; |
12 | use BrianHenryIE\Strauss\Helpers\FileSystem; |
13 | use BrianHenryIE\Strauss\Pipeline\Autoload\DumpAutoload; |
14 | use BrianHenryIE\Strauss\Pipeline\Cleanup\InstalledJson; |
15 | use BrianHenryIE\Strauss\Types\DiscoveredSymbols; |
16 | use Psr\Log\LoggerAwareTrait; |
17 | use Psr\Log\LoggerInterface; |
18 | use Psr\Log\NullLogger; |
19 | |
20 | class Autoload |
21 | { |
22 | use LoggerAwareTrait; |
23 | |
24 | protected FileSystem $filesystem; |
25 | |
26 | protected AutoloadConfigInterface $config; |
27 | |
28 | /** |
29 | * The files autoloaders of packages that have been copied by Strauss. |
30 | * Keyed by package path. |
31 | * |
32 | * @var array<string, array<string>> $discoveredFilesAutoloaders Array of packagePath => array of relativeFilePaths. |
33 | */ |
34 | protected array $discoveredFilesAutoloaders; |
35 | |
36 | protected string $absoluteTargetDirectory; |
37 | |
38 | /** |
39 | * Autoload constructor. |
40 | * |
41 | * @param StraussConfig $config |
42 | * @param array<string, array<string>> $discoveredFilesAutoloaders |
43 | */ |
44 | public function __construct( |
45 | AutoloadConfigInterface $config, |
46 | array $discoveredFilesAutoloaders, |
47 | Filesystem $filesystem, |
48 | ?LoggerInterface $logger = null |
49 | ) { |
50 | $this->config = $config; |
51 | $this->discoveredFilesAutoloaders = $discoveredFilesAutoloaders; |
52 | $this->filesystem = $filesystem; |
53 | $this->setLogger($logger ?? new NullLogger()); |
54 | } |
55 | |
56 | public function generate(array $flatDependencyTree, DiscoveredSymbols $discoveredSymbols): void |
57 | { |
58 | if (!$this->config->isClassmapOutput()) { |
59 | $this->logger->debug('Not generating autoload.php because classmap output is disabled.'); |
60 | // TODO: warn about `files` autoloaders. |
61 | // TODO: list the files autoloaders that will be missed. |
62 | return; |
63 | } |
64 | |
65 | $this->logger->info('Generating autoload files for ' . $this->config->getTargetDirectory()); |
66 | |
67 | if ($this->config->getVendorDirectory() !== $this->config->getTargetDirectory()) { |
68 | $installedJson = new InstalledJson( |
69 | $this->config, |
70 | $this->filesystem, |
71 | $this->logger |
72 | ); |
73 | $installedJson->createAndCleanTargetDirInstalledJson($flatDependencyTree, $discoveredSymbols); |
74 | } |
75 | |
76 | (new DumpAutoload( |
77 | $this->config, |
78 | $this->filesystem, |
79 | $this->logger, |
80 | new Prefixer( |
81 | $this->config, |
82 | $this->filesystem, |
83 | $this->logger |
84 | ), |
85 | new FileEnumerator( |
86 | $this->config, |
87 | $this->filesystem |
88 | ) |
89 | ))->generatedPrefixedAutoloader(); |
90 | } |
91 | } |