@@ -36,26 +36,53 @@ public function load(array $configs, ContainerBuilder $container)
36
36
*/
37
37
private function setMappings (ContainerBuilder $ container , $ config )
38
38
{
39
- if (true === \file_exists ($ config ['mappings ' ])) {
40
- $ finder = new Finder ();
41
- $ finder ->files ()->in ($ config ['mappings ' ]);
42
- $ loadedMappings = [];
39
+ $ definition = new Definition ();
40
+ $ definition ->setClass ('NilPortugues\Api\Mapping\Mapper ' );
41
+ $ args = $ this ->resolveMappings ($ container , $ config ['mappings ' ]);
42
+ $ definition ->setArguments ($ args );
43
+ $ definition ->setLazy (true );
43
44
44
- foreach ($ finder as $ file ) {
45
- /* @var \Symfony\Component\Finder\SplFileInfo $file */
46
- $ mapping = \file_get_contents ($ file ->getPathname ());
47
- $ mapping = Yaml::parse ($ mapping );
48
- $ loadedMappings [] = $ mapping ['mapping ' ];
45
+ $ container ->setDefinition ('nil_portugues.api.mapping.mapper ' , $ definition );
46
+ }
47
+
48
+ private function resolveMappings (ContainerBuilder $ container , $ mappings )
49
+ {
50
+ $ loadedMappings = [];
51
+
52
+ foreach ($ mappings as $ mapping ) {
53
+ if (0 === strpos ($ mapping , '@ ' )) {
54
+ $ name = substr ($ mapping , 1 , strpos ($ mapping , '/ ' ) - 1 );
55
+
56
+ $ dir = $ this ->resolveBundle ($ container , $ name );
57
+ $ mapping = str_replace ('@ ' .$ name , $ dir , $ mapping );
58
+ }
59
+
60
+ if (true === \file_exists ($ mapping )) {
61
+ $ finder = new Finder ();
62
+ $ finder ->files ()->in ($ mapping );
63
+ foreach ($ finder as $ file ) {
64
+ /* @var \Symfony\Component\Finder\SplFileInfo $file */
65
+ $ mapping = \file_get_contents ($ file ->getPathname ());
66
+ $ mapping = Yaml::parse ($ mapping );
67
+ $ loadedMappings [] = $ mapping ['mapping ' ];
68
+ }
49
69
}
70
+ }
71
+
72
+ return [$ loadedMappings ];
73
+ }
50
74
51
- $ definition = new Definition ();
52
- $ definition ->setClass ('NilPortugues\Api\Mapping\Mapper ' );
53
- $ args = array ($ loadedMappings );
54
- $ definition ->setArguments ($ args );
55
- $ definition ->setLazy (true );
75
+ private function resolveBundle (ContainerBuilder $ container , $ name )
76
+ {
77
+ $ bundles = $ container ->getParameter ('kernel.bundles ' );
56
78
57
- $ container ->setDefinition ('nil_portugues.api.mapping.mapper ' , $ definition );
79
+ if (!isset ($ bundles [$ name ])) {
80
+ return null ;
58
81
}
82
+
83
+ $ class = $ bundles [$ name ];
84
+ $ refClass = new \ReflectionClass ($ class );
85
+ return dirname ($ refClass ->getFileName ());
59
86
}
60
87
61
88
/**
0 commit comments