1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace PHPDIDefinitions; |
||
6 | |||
7 | use function glob; |
||
8 | use function is_array; |
||
9 | use function strpos; |
||
10 | use function WyriHaximus\get_in_packages_composer_path; |
||
11 | 1 | ||
12 | final class DefinitionsGatherer |
||
13 | 1 | { |
|
14 | 1 | private const string LOCATION = 'extra.php-di-definitions.di'; |
|
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
15 | |||
16 | 1 | /** @return iterable<string, mixed> */ |
|
17 | public static function gather(string $location = self::LOCATION): iterable |
||
18 | 1 | { |
|
19 | 1 | yield from self::requires(get_in_packages_composer_path($location)); |
|
20 | } |
||
21 | 1 | ||
22 | /** |
||
23 | 1 | * @param iterable<string> $files |
|
24 | * |
||
25 | 1 | * @return iterable<string, mixed> |
|
26 | 1 | */ |
|
27 | private static function requires(iterable $files): iterable |
||
28 | 1 | { |
|
29 | foreach ($files as $file) { |
||
30 | yield from self::require($file); |
||
31 | 1 | } |
|
32 | 1 | } |
|
33 | |||
34 | /** @return iterable<string, mixed> */ |
||
35 | private static function require(string $file): iterable |
||
36 | { |
||
37 | if (strpos($file, '*') !== false) { |
||
38 | $files = glob($file); |
||
39 | if (! is_array($files)) { |
||
40 | return; |
||
41 | } |
||
42 | |||
43 | yield from self::requires($files); |
||
44 | |||
45 | return; |
||
46 | } |
||
47 | |||
48 | /** @phpstan-ignore generator.keyType */ |
||
49 | yield from require $file; |
||
50 | } |
||
51 | } |
||
52 |