PluginProbe
Code Snippets / 4.0.0-beta.2
Code Snippets v4.0.0-beta.2
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / vendor / typisttech / imposter-plugin / src / AutoloadMerger.php

AutoloadMerger.php in Code Snippets 4.0.0-beta.2, at vendor/typisttech/imposter-plugin/src/AutoloadMerger.php

41 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace TypistTech\Imposter\Plugin;
6
7 use Composer\Package\RootPackageInterface;
8 use RuntimeException;
9 use TypistTech\Imposter\ImposterFactory;
10
11 class AutoloadMerger
12 {
13 public static function run(RootPackageInterface $package): void
14 {
15 $autoload = $package->getAutoload();
16 $autoload = array_merge_recursive($autoload, [
17 'classmap' => static::getImposterAutoloads(),
18 ]);
19
20 $package->setAutoload($autoload);
21 }
22
23 /**
24 * @return string[]
25 * @todo [Help Wanted] Think of a better way to handle file not found during installation
26 */
27 protected static function getImposterAutoloads(): array
28 {
29 try {
30 $cwd = getcwd();
31 $imposter = ImposterFactory::forProject($cwd, ['typisttech/imposter-plugin']);
32
33 return array_map(function ($path) use ($cwd): string {
34 return str_replace($cwd . '/', '', $path);
35 }, $imposter->getAutoloads());
36 } catch (RuntimeException $exception) {
37 return [];
38 }
39 }
40 }
41