|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace Innmind\Rest\ServerBundle\DependencyInjection\Compiler; |
|
5
|
|
|
|
|
6
|
|
|
use Innmind\Filesystem\{ |
|
7
|
|
|
Adapter\FilesystemAdapter, |
|
8
|
|
|
Directory, |
|
9
|
|
|
Exception\FileNotFound |
|
10
|
|
|
}; |
|
11
|
|
|
use Innmind\Immutable\{ |
|
12
|
|
|
Set, |
|
13
|
|
|
SetInterface |
|
14
|
|
|
}; |
|
15
|
|
|
use Symfony\Component\DependencyInjection\{ |
|
16
|
|
|
ContainerBuilder, |
|
17
|
|
|
Compiler\CompilerPassInterface |
|
18
|
|
|
}; |
|
19
|
|
|
|
|
20
|
|
|
final class RegisterDefinitionFilesPass implements CompilerPassInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
46 |
|
public function process(ContainerBuilder $container) |
|
26
|
|
|
{ |
|
27
|
46 |
|
$bundles = $container->getParameter('kernel.bundles'); |
|
28
|
46 |
|
$files = new Set('string'); |
|
29
|
|
|
|
|
30
|
46 |
|
foreach ($bundles as $bundle => $class) { |
|
31
|
38 |
|
$files = $files->merge( |
|
32
|
38 |
|
$this->searchFiles($class) |
|
33
|
|
|
); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$container |
|
37
|
46 |
|
->getDefinition('innmind_rest_server.definition.directories') |
|
38
|
46 |
|
->addArgument($files->toPrimitive()); |
|
39
|
46 |
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* @param string $class |
|
43
|
|
|
* @return SetInterface<string> |
|
|
|
|
|
|
44
|
|
|
*/ |
|
45
|
38 |
|
private function searchFiles(string $class): SetInterface |
|
46
|
|
|
{ |
|
47
|
38 |
|
$files = new Set('string'); |
|
48
|
|
|
|
|
49
|
|
|
try { |
|
50
|
38 |
|
$refl = new \ReflectionClass($class); |
|
51
|
38 |
|
$path = dirname($refl->getFileName()); |
|
52
|
38 |
|
$config = (new FilesystemAdapter($path)) |
|
|
|
|
|
|
53
|
38 |
|
->get('Resources') |
|
54
|
38 |
|
->get('config'); |
|
55
|
38 |
|
$path .= '/Resources/config'; |
|
56
|
|
|
|
|
57
|
38 |
|
if ($config->has('rest.yml')) { |
|
58
|
38 |
|
return $files->add($path.'/rest.yml'); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
2 |
|
$folder = $config->get('rest'); |
|
62
|
|
|
|
|
63
|
2 |
|
foreach ($folder as $file) { |
|
64
|
2 |
|
if ($file instanceof Directory) { |
|
65
|
2 |
|
continue; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
2 |
|
$files = $files->add( |
|
69
|
2 |
|
$path.'/rest/'.$file->name() |
|
70
|
|
|
); |
|
71
|
|
|
} |
|
72
|
2 |
|
} catch (FileNotFound $e) { |
|
73
|
|
|
//pass |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
2 |
|
return $files; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.