@@ -17,6 +17,7 @@ class PathTemplateResolver
1717
1818 /** @var string - base path for the project */
1919 protected $ base_path ;
20+ protected $ normalized_base_path ;
2021
2122 // used during loading of language file list
2223 protected $ lang_files ;
@@ -28,52 +29,52 @@ class PathTemplateResolver
2829 protected $ group_sep ;
2930
3031 protected static $ defaults = array (
31- 'lang ' => [
32+ 'lang ' => [
3233 'db_group ' => '{group} ' ,
33- 'root ' => '' ,
34- 'json ' => [
34+ 'root ' => '' ,
35+ 'json ' => [
3536 '* ' => '/resources/lang/{locale}.json ' ,
3637 ],
37- 'files ' => [
38+ 'files ' => [
3839 '4 ' => '/app/lang/{locale}/{group} ' ,
3940 '* ' => '/resources/lang/{locale}/{group} ' ,
4041 ],
41- 'vars ' => [
42- '{vendor} ' => '' ,
42+ 'vars ' => [
43+ '{vendor} ' => '' ,
4344 '{package} ' => '' ,
4445 ],
4546 ],
46- 'packages ' => [
47+ 'packages ' => [
4748 'db_group ' => '{package}::{group} ' ,
48- 'include ' => '* ' ,
49- 'root ' => '' ,
50- 'files ' => [
49+ 'include ' => '* ' ,
50+ 'root ' => '' ,
51+ 'files ' => [
5152 '4 ' => '/app/lang/packages/{locale}/{package}/{group} ' ,
5253 '* ' => '/resources/lang/vendor/{package}/{locale}/{group} ' ,
5354 ],
54- 'vars ' => [
55+ 'vars ' => [
5556 '{vendor} ' => '' ,
5657 ],
5758 ],
5859 'workbench ' => [
5960 'db_group ' => 'wbn:{vendor}.{package}::{group} ' ,
60- 'include ' => '*/* ' ,
61- 'root ' => '/workbench/{vendor}/{package} ' ,
62- 'files ' => [
61+ 'include ' => '*/* ' ,
62+ 'root ' => '/workbench/{vendor}/{package} ' ,
63+ 'files ' => [
6364 '4 ' => 'src/lang/{locale}/{group} ' ,
6465 '* ' => 'resources/lang/{locale}/{group} ' ,
6566 ],
66- 'vars ' => [],
67+ 'vars ' => [],
6768 ],
68- 'vendor ' => [
69+ 'vendor ' => [
6970 'db_group ' => 'vnd:{vendor}.{package}::{group} ' ,
70- 'include ' => [],
71- 'root ' => '/vendor/{vendor}/{package} ' ,
72- 'files ' => [
71+ 'include ' => [],
72+ 'root ' => '/vendor/{vendor}/{package} ' ,
73+ 'files ' => [
7374 '4 ' => 'src/lang/{locale}/{group} ' ,
7475 '* ' => 'resources/lang/{locale}/{group} ' ,
7576 ],
76- 'vars ' => [],
77+ 'vars ' => [],
7778 ],
7879 //// these will be merged with vendor or workbench type and create their own types named by the package
7980 //// the first section whose include is satisfied will be used, the other ignored. Since vendor section requires
@@ -108,6 +109,8 @@ public function __construct($files, $base_path, $config, $version)
108109 $ this ->version = $ version ;
109110 $ this ->group_sep = ". " ;
110111
112+ $ this ->normalized_base_path = str_replace ("\\" , "/ " , $ base_path );
113+
111114 // provide default mappings if needed. and normalize the config
112115 static ::normalizeConfig ($ config , $ version );
113116
@@ -137,9 +140,9 @@ public static function normalizeConfig(&$config, $version)
137140 }
138141 }
139142 }
140- } elseif (array_key_exists ('__merge ' , $ value )) {
143+ } else if (array_key_exists ('__merge ' , $ value )) {
141144 $ toMerge [] = $ key ;
142- } elseif ($ key [0 ] === '_ ' && $ key [1 ] === '_ ' ) {
145+ } else if ($ key [0 ] === '_ ' && $ key [1 ] === '_ ' ) {
143146 // just handle the includes sub-key
144147 if (!array_key_exists ('include ' , $ value )) {
145148 $ value ['include ' ] = [];
@@ -190,15 +193,14 @@ public static function normalizeConfig(&$config, $version)
190193 public static function normalizeInclude ($ value )
191194 {
192195 if (array_key_exists ('include ' , $ value )) {
193-
194196 if (!is_array ($ value ['include ' ])) $ value ['include ' ] = $ value ['include ' ] ? array ($ value ['include ' ]) : [];
195197
196198 $ includeNormalize = [];
197199 if (!array_key_exists ('{vendor} ' , $ value ['vars ' ]) || $ value ['vars ' ]['{vendor} ' ] !== null ) {
198200 // this type has vendor
199201 $ includeNormalize ['|^/| ' ] = '*/ ' ;
200202 $ includeNormalize ['|/$| ' ] = '/* ' ;
201- } elseif (!array_key_exists ('{package} ' , $ value ['vars ' ]) || $ value ['vars ' ]['{package} ' ] !== null ) {
203+ } else if (!array_key_exists ('{package} ' , $ value ['vars ' ]) || $ value ['vars ' ]['{package} ' ] !== null ) {
202204 // this type has package only
203205 $ includeNormalize ['|^/$| ' ] = '* ' ;
204206 }
@@ -223,7 +225,7 @@ public static function configValues($config, $setting)
223225 if (!is_array ($ value [$ setting ]) && !array_key_exists ($ value [$ setting ], $ values )) {
224226 $ values [$ value [$ setting ]] = $ value + ['section ' => $ key ];
225227 }
226- } elseif ($ setting === 'path ' && !is_array ($ value )) {
228+ } else if ($ setting === 'path ' && !is_array ($ value )) {
227229 if (!array_key_exists ($ value , $ values )) {
228230 $ values [$ value ] = ['section ' => $ key , 'path ' => $ value ];
229231 }
@@ -331,7 +333,7 @@ public static function isPathIncluded($config, $vars, $partial = true)
331333 if (!$ matchPackage ) {
332334 // vendor must be known at this point and partials allowed
333335 if (($ vendor === '* ' || $ vendor === $ vars_vendor )) return true ;
334- } elseif (!$ matchVendor ) {
336+ } else if (!$ matchVendor ) {
335337 // package must be known at this point and partials allowed
336338 if ($ package === '* ' || $ package === $ vars_package ) return true ;
337339 } else {
@@ -348,8 +350,10 @@ protected function loadFileList($prefix, $path_parts, $group_parts)
348350 $ prefix = str_replace ("\\" , "/ " , $ prefix );
349351
350352 for (; ;) {
351- if (array_key_exists ($ prefix , $ this ->processed_dirs ) || ($ prefix != '/ ' && (!file_exists ($ prefix ) || !is_dir ($ prefix )))) {
352- // already handled this one or it does not exist
353+ if (array_key_exists ($ prefix , $ this ->processed_dirs )
354+ || (($ prefix != $ this ->normalized_base_path && !str_starts_with ($ this ->normalized_base_path . '/ ' , $ prefix . '/ ' ))
355+ && (!file_exists ($ prefix ) || !is_dir ($ prefix )))) {
356+ // already handled this one or it does not exist and not under base dir
353357 return ;
354358 }
355359
@@ -472,7 +476,7 @@ public static function getDbGroupPath($config, $group, $locale)
472476 // call groupFilePath, not this static method
473477 return null ;
474478 }
475-
479+
476480 $ db_group = $ config ['db_group ' ];
477481 $ path = $ config ['path ' ];
478482 if ($ vars = static ::extractTemplateVars ($ db_group , $ group )) {
0 commit comments