1111
1212namespace Symfony \Component \DependencyInjection \Loader ;
1313
14+ use Symfony \Component \Config \Exception \FileLocatorFileNotFoundException ;
1415use Symfony \Component \DependencyInjection \ContainerBuilder ;
1516use Symfony \Component \DependencyInjection \Definition ;
1617use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
@@ -40,6 +41,22 @@ public function __construct(ContainerBuilder $container, FileLocatorInterface $l
4041 parent ::__construct ($ locator );
4142 }
4243
44+ /**
45+ * {@inheritdoc}
46+ */
47+ public function import ($ resource , $ type = null , $ ignoreErrors = false , $ sourceResource = null )
48+ {
49+ try {
50+ foreach ($ this ->glob ($ resource , false ) as $ path => $ info ) {
51+ parent ::import ($ path , $ type , $ ignoreErrors , $ sourceResource );
52+ }
53+ } catch (FileLocatorFileNotFoundException $ e ) {
54+ if (!$ ignoreErrors ) {
55+ throw $ e ;
56+ }
57+ }
58+ }
59+
4360 /**
4461 * Registers a set of classes as services using PSR-4 for discovery.
4562 *
@@ -73,7 +90,7 @@ private function findClasses($namespace, $resource)
7390 $ extRegexp = defined ('HHVM_VERSION ' ) ? '/ \\.(?:php|hh)$/ ' : '/ \\.php$/ ' ;
7491
7592 foreach ($ this ->glob ($ resource , true , $ prefixLen ) as $ path => $ info ) {
76- if (!preg_match ($ extRegexp , $ path , $ m ) || !$ info ->isFile () || ! $ info -> isReadable ()) {
93+ if (!preg_match ($ extRegexp , $ path , $ m ) || !$ info ->isReadable ()) {
7794 continue ;
7895 }
7996 $ class = $ namespace .ltrim (str_replace ('/ ' , '\\' , substr ($ path , $ prefixLen , -strlen ($ m [0 ]))), '\\' );
@@ -95,6 +112,11 @@ private function findClasses($namespace, $resource)
95112 private function glob ($ resource , $ recursive , &$ prefixLen = null )
96113 {
97114 if (strlen ($ resource ) === $ i = strcspn ($ resource , '*?{[ ' )) {
115+ if (!$ recursive ) {
116+ yield $ resource => new \SplFileInfo ($ resource );
117+
118+ return ;
119+ }
98120 $ resourcePrefix = $ resource ;
99121 $ resource = '' ;
100122 } elseif (0 === $ i ) {
@@ -117,9 +139,11 @@ private function glob($resource, $recursive, &$prefixLen = null)
117139 if ($ recursive && is_dir ($ path )) {
118140 $ flags = \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS ;
119141 foreach (new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ path , $ flags )) as $ path => $ info ) {
120- yield $ path => $ info ;
142+ if ($ info ->isFile ()) {
143+ yield $ path => $ info ;
144+ }
121145 }
122- } else {
146+ } elseif ( is_file ( $ path )) {
123147 yield $ path => new \SplFileInfo ($ path );
124148 }
125149 }
@@ -138,7 +162,7 @@ private function glob($resource, $recursive, &$prefixLen = null)
138162 }
139163
140164 foreach ($ finder ->followLinks ()->in ($ resourcePrefix ) as $ path => $ info ) {
141- if (preg_match ($ regex , substr ($ path , $ prefixLen ))) {
165+ if (preg_match ($ regex , substr ($ path , $ prefixLen )) && $ info -> isFile () ) {
142166 yield $ path => $ info ;
143167 }
144168 }
0 commit comments