11
11
12
12
namespace Symfony \Component \DependencyInjection \Loader ;
13
13
14
+ use Symfony \Component \Config \Exception \FileLocatorFileNotFoundException ;
14
15
use Symfony \Component \DependencyInjection \ContainerBuilder ;
15
16
use Symfony \Component \DependencyInjection \Definition ;
16
17
use Symfony \Component \DependencyInjection \Exception \InvalidArgumentException ;
@@ -40,6 +41,22 @@ public function __construct(ContainerBuilder $container, FileLocatorInterface $l
40
41
parent ::__construct ($ locator );
41
42
}
42
43
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
+
43
60
/**
44
61
* Registers a set of classes as services using PSR-4 for discovery.
45
62
*
@@ -73,7 +90,7 @@ private function findClasses($namespace, $resource)
73
90
$ extRegexp = defined ('HHVM_VERSION ' ) ? '/ \\.(?:php|hh)$/ ' : '/ \\.php$/ ' ;
74
91
75
92
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 ()) {
77
94
continue ;
78
95
}
79
96
$ class = $ namespace .ltrim (str_replace ('/ ' , '\\' , substr ($ path , $ prefixLen , -strlen ($ m [0 ]))), '\\' );
@@ -95,6 +112,11 @@ private function findClasses($namespace, $resource)
95
112
private function glob ($ resource , $ recursive , &$ prefixLen = null )
96
113
{
97
114
if (strlen ($ resource ) === $ i = strcspn ($ resource , '*?{[ ' )) {
115
+ if (!$ recursive ) {
116
+ yield $ resource => new \SplFileInfo ($ resource );
117
+
118
+ return ;
119
+ }
98
120
$ resourcePrefix = $ resource ;
99
121
$ resource = '' ;
100
122
} elseif (0 === $ i ) {
@@ -117,9 +139,11 @@ private function glob($resource, $recursive, &$prefixLen = null)
117
139
if ($ recursive && is_dir ($ path )) {
118
140
$ flags = \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS ;
119
141
foreach (new \RecursiveIteratorIterator (new \RecursiveDirectoryIterator ($ path , $ flags )) as $ path => $ info ) {
120
- yield $ path => $ info ;
142
+ if ($ info ->isFile ()) {
143
+ yield $ path => $ info ;
144
+ }
121
145
}
122
- } else {
146
+ } elseif ( is_file ( $ path )) {
123
147
yield $ path => new \SplFileInfo ($ path );
124
148
}
125
149
}
@@ -138,7 +162,7 @@ private function glob($resource, $recursive, &$prefixLen = null)
138
162
}
139
163
140
164
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 () ) {
142
166
yield $ path => $ info ;
143
167
}
144
168
}
0 commit comments