@@ -59,23 +59,37 @@ public function getLocator()
5959 /**
6060 * Imports a resource.
6161 *
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
6667 *
6768 * @return mixed
6869 *
6970 * @throws LoaderLoadException
7071 * @throws FileLoaderImportCircularReferenceException
7172 * @throws FileLocatorFileNotFoundException
7273 */
73- public function import ($ resource , $ type = null , $ ignoreErrors = false , $ sourceResource = null )
74+ public function import ($ resource , $ type = null , $ ignoreErrors = false , $ sourceResource = null /*, $exclude = null*/ )
7475 {
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+
7581 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+
7690 $ ret = [];
7791 $ 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 ) {
7993 if (null !== $ res = $ this ->doImport ($ path , $ type , $ ignoreErrors , $ sourceResource )) {
8094 $ ret [] = $ res ;
8195 }
0 commit comments