@@ -59,23 +59,37 @@ public function getLocator()
59
59
/**
60
60
* Imports a resource.
61
61
*
62
- * @param mixed $resource A Resource
63
- * @param string|null $type The resource type or null if unknown
64
- * @param bool $ignoreErrors Whether to ignore import errors or not
65
- * @param string|null $sourceResource The original resource importing the new resource
62
+ * @param mixed $resource A Resource
63
+ * @param string|null $type The resource type or null if unknown
64
+ * @param bool $ignoreErrors Whether to ignore import errors or not
65
+ * @param string|null $sourceResource The original resource importing the new resource
66
+ * @param string|string[]|null $exclude Glob patterns to exclude from the import
66
67
*
67
68
* @return mixed
68
69
*
69
70
* @throws LoaderLoadException
70
71
* @throws FileLoaderImportCircularReferenceException
71
72
* @throws FileLocatorFileNotFoundException
72
73
*/
73
- public function import ($ resource , $ type = null , $ ignoreErrors = false , $ sourceResource = null )
74
+ public function import ($ resource , $ type = null , $ ignoreErrors = false , $ sourceResource = null /*, $exclude = null*/ )
74
75
{
76
+ if (\func_num_args () < 5 && __CLASS__ !== \get_class ($ this ) && __CLASS__ !== (new \ReflectionMethod ($ this , __FUNCTION__ ))->getDeclaringClass ()->getName () && !$ this instanceof \PHPUnit \Framework \MockObject \MockObject && !$ this instanceof \Prophecy \Prophecy \ProphecySubjectInterface) {
77
+ @trigger_error (sprintf ('The "%s()" method will have a new "$exclude = null" argument in version 5.0, not defining it is deprecated since Symfony 4.4. ' , __METHOD__ ), E_USER_DEPRECATED );
78
+ }
79
+ $ exclude = \func_num_args () >= 5 ? func_get_arg (4 ) : null ;
80
+
75
81
if (\is_string ($ resource ) && \strlen ($ resource ) !== $ i = strcspn ($ resource , '*?{[ ' )) {
82
+ $ excluded = [];
83
+ foreach ((array ) $ exclude as $ pattern ) {
84
+ foreach ($ this ->glob ($ pattern , true , $ _ , false , true ) as $ path => $ info ) {
85
+ // normalize Windows slashes
86
+ $ excluded [str_replace ('\\' , '/ ' , $ path )] = true ;
87
+ }
88
+ }
89
+
76
90
$ ret = [];
77
91
$ isSubpath = 0 !== $ i && false !== strpos (substr ($ resource , 0 , $ i ), '/ ' );
78
- foreach ($ this ->glob ($ resource , false , $ _ , $ ignoreErrors || !$ isSubpath ) as $ path => $ info ) {
92
+ foreach ($ this ->glob ($ resource , false , $ _ , $ ignoreErrors || !$ isSubpath, false , $ excluded ) as $ path => $ info ) {
79
93
if (null !== $ res = $ this ->doImport ($ path , $ type , $ ignoreErrors , $ sourceResource )) {
80
94
$ ret [] = $ res ;
81
95
}
0 commit comments