@@ -143,7 +143,7 @@ public static function composeDataSets(array $files)
143143 {
144144 $ result = [];
145145 foreach ($ files as $ file ) {
146- $ key = str_replace (BP . '/ ' , '' , $ file );
146+ $ key = $ file !== null ? str_replace (BP . '/ ' , '' , $ file ) : '' ;
147147 $ result [$ key ] = [$ file ];
148148 }
149149 return $ result ;
@@ -640,9 +640,10 @@ private function collectModuleLayoutFiles(array $params, $location)
640640 );
641641 if ($ params ['with_metainfo ' ]) {
642642 foreach ($ moduleFiles as $ moduleFile ) {
643- $ modulePath = str_replace (DIRECTORY_SEPARATOR , '/ ' , preg_quote ($ moduleDir , '# ' ));
643+ $ modulePath = $ moduleDir !== null ?
644+ str_replace (DIRECTORY_SEPARATOR , '/ ' , preg_quote ($ moduleDir , '# ' )) : '' ;
644645 $ regex = '#^ ' . $ modulePath . '/view/(?P<area>[a-z]+)/layout/(?P<path>.+)$#i ' ;
645- if (preg_match ($ regex , $ moduleFile , $ matches )) {
646+ if ($ moduleFile && preg_match ($ regex , $ moduleFile , $ matches )) {
646647 $ files [] = [
647648 [$ matches ['area ' ], '' , $ moduleName , $ matches ['path ' ], $ moduleFile ]
648649 ];
@@ -673,7 +674,8 @@ private function collectThemeLayoutFiles(array $params, $location)
673674 $ requiredModuleName = $ params ['namespace ' ] . '_ ' . $ params ['module ' ];
674675 $ themePath = $ params ['theme_path ' ];
675676 foreach ($ this ->themePackageList ->getThemes () as $ theme ) {
676- $ currentThemePath = str_replace (DIRECTORY_SEPARATOR , '/ ' , $ theme ->getPath ());
677+ $ currentThemePath = $ theme ->getPath () !== null ?
678+ str_replace (DIRECTORY_SEPARATOR , '/ ' , $ theme ->getPath ()) : '' ;
677679 $ currentThemeCode = $ theme ->getVendor () . '/ ' . $ theme ->getName ();
678680 if (($ area == '* ' || $ theme ->getArea () === $ area )
679681 && ($ themePath == '* ' || $ themePath == '*/* ' || $ themePath == $ currentThemeCode )
@@ -712,7 +714,7 @@ private function parseThemeFiles($themeFiles, $currentThemePath, $theme)
712714 . '/(?P<module>[a-z\d]+_[a-z\d]+)/layout/(override/((base/)|(theme/[a-z\d_]+/[a-z\d_]+/)))? '
713715 . '(?P<path>.+)$#i ' ;
714716 foreach ($ themeFiles as $ themeFile ) {
715- if (preg_match ($ regex , $ themeFile , $ matches )) {
717+ if ($ themeFile && preg_match ($ regex , $ themeFile , $ matches )) {
716718 $ files [] = [
717719 $ theme ->getArea (),
718720 $ theme ->getVendor () . '/ ' . $ theme ->getName (),
@@ -927,7 +929,8 @@ private function accumulateThemeStaticFiles($area, $locale, $filePattern, &$resu
927929 $ themeArea = $ themePackage ->getArea ();
928930 if ($ area == '* ' || $ area == $ themeArea ) {
929931 $ files = [];
930- $ themePath = str_replace (DIRECTORY_SEPARATOR , '/ ' , $ themePackage ->getPath ());
932+ $ themePath = $ themePackage ->getPath () !== null ?
933+ str_replace (DIRECTORY_SEPARATOR , '/ ' , $ themePackage ->getPath ()) : '' ;
931934 $ paths = [
932935 $ themePath . "/web " ,
933936 $ themePath . "/*_*/web " ,
@@ -938,7 +941,7 @@ private function accumulateThemeStaticFiles($area, $locale, $filePattern, &$resu
938941 $ regex = '#^ ' . $ themePath .
939942 '/((?P<module>[a-z\d]+_[a-z_\d]+)/)?web/(i18n/(?P<locale>[a-z_]+)/)?(?P<path>.+)$#i ' ;
940943 foreach ($ files as $ file ) {
941- if (preg_match ($ regex , $ file , $ matches )) {
944+ if ($ file && preg_match ($ regex , $ file , $ matches )) {
942945 $ result [] = [
943946 $ themeArea ,
944947 $ themePackage ->getVendor () . '/ ' . $ themePackage ->getName (),
@@ -1004,7 +1007,7 @@ protected function _accumulateFilesByPatterns(array $patterns, $filePattern, arr
10041007 {
10051008 $ path = str_replace (DIRECTORY_SEPARATOR , '/ ' , BP );
10061009 foreach (self ::getFiles ($ patterns , $ filePattern ) as $ file ) {
1007- $ file = str_replace (DIRECTORY_SEPARATOR , '/ ' , $ file );
1010+ $ file = $ file !== null ? str_replace (DIRECTORY_SEPARATOR , '/ ' , $ file ) : '' ;
10081011 if ($ subroutine ) {
10091012 $ result [] = $ this ->$ subroutine ($ file , $ path );
10101013 } else {
@@ -1024,7 +1027,7 @@ protected function _accumulateFilesByPatterns(array $patterns, $filePattern, arr
10241027 protected function _parseModuleStatic ($ file )
10251028 {
10261029 foreach ($ this ->componentRegistrar ->getPaths (ComponentRegistrar::MODULE ) as $ moduleName => $ modulePath ) {
1027- if (preg_match (
1030+ if ($ file && preg_match (
10281031 '/^ ' . preg_quote ("{$ modulePath }/ " , '/ ' ) . 'view\/([a-z]+)\/web\/(.+)$/i ' ,
10291032 $ file ,
10301033 $ matches
@@ -1051,7 +1054,7 @@ private function accumulateStaticFiles($area, $filePattern, array &$result)
10511054 $ moduleWebPath = $ moduleDir . "/view/ {$ area }/web " ;
10521055
10531056 foreach (self ::getFiles ([$ moduleWebPath ], $ filePattern ) as $ absolutePath ) {
1054- $ localPath = substr ($ absolutePath , strlen ($ moduleDir ) + 1 );
1057+ $ localPath = $ absolutePath !== null ? substr ($ absolutePath , strlen ($ moduleDir ?? '' ) + 1 ) : '' ;
10551058 if (preg_match ('/^view\/([a-z]+)\/web\/(.+)$/i ' , $ localPath , $ matches ) === 1 ) {
10561059 list (, $ parsedArea , $ parsedPath ) = $ matches ;
10571060 $ result [] = [$ parsedArea , '' , '' , $ moduleName , $ parsedPath , $ absolutePath ];
@@ -1070,7 +1073,8 @@ protected function _parseModuleLocaleStatic($file)
10701073 {
10711074 foreach ($ this ->componentRegistrar ->getPaths (ComponentRegistrar::MODULE ) as $ moduleName => $ modulePath ) {
10721075 $ appCode = preg_quote ("{$ modulePath }/ " , '/ ' );
1073- if (preg_match ('/^ ' . $ appCode . 'view\/([a-z]+)\/web\/i18n\/([a-z_]+)\/(.+)$/i ' , $ file , $ matches ) === 1 ) {
1076+ if ($ file &&
1077+ preg_match ('/^ ' . $ appCode . 'view\/([a-z]+)\/web\/i18n\/([a-z_]+)\/(.+)$/i ' , $ file , $ matches ) === 1 ) {
10741078 list (, $ area , $ locale , $ filePath ) = $ matches ;
10751079 return [$ area , '' , $ locale , $ moduleName , $ filePath , $ file ];
10761080 }
@@ -1191,10 +1195,10 @@ private function accumulateThemeTemplateFiles($withMetaInfo, array &$result)
11911195 $ files
11921196 );
11931197 if ($ withMetaInfo ) {
1194- $ regex = ' #^ ' . str_replace (DIRECTORY_SEPARATOR , '/ ' , $ theme ->getPath ())
1195- . '/(?P<module>[a-z\d]+_[a-z\d]+)/templates/(?P<path>.+)$#i ' ;
1198+ $ themePath = $ theme -> getPath () !== null ? str_replace (DIRECTORY_SEPARATOR , '/ ' , $ theme ->getPath ()) : '' ;
1199+ $ regex = ' #^ ' . $ themePath . '/(?P<module>[a-z\d]+_[a-z\d]+)/templates/(?P<path>.+)$#i ' ;
11961200 foreach ($ files as $ file ) {
1197- if (preg_match ($ regex , $ file , $ matches )) {
1201+ if ($ file && preg_match ($ regex , $ file , $ matches )) {
11981202 $ result [] = [
11991203 $ theme ->getArea (),
12001204 $ theme ->getVendor () . '/ ' . $ theme ->getName (),
@@ -1230,10 +1234,11 @@ private function accumulateModuleTemplateFiles($withMetaInfo, array &$result)
12301234 $ files
12311235 );
12321236 if ($ withMetaInfo ) {
1233- $ modulePath = str_replace (DIRECTORY_SEPARATOR , '/ ' , preg_quote ($ moduleDir , '# ' ));
1237+ $ modulePath = $ moduleDir !== null ?
1238+ str_replace (DIRECTORY_SEPARATOR , '/ ' , preg_quote ($ moduleDir , '# ' )) : '' ;
12341239 $ regex = '#^ ' . $ modulePath . '/view/(?P<area>[a-z]+)/templates/(?P<path>.+)$#i ' ;
12351240 foreach ($ files as $ file ) {
1236- if (preg_match ($ regex , $ file , $ matches )) {
1241+ if ($ file && preg_match ($ regex , $ file , $ matches )) {
12371242 $ result [] = [
12381243 $ matches ['area ' ],
12391244 '' ,
@@ -1320,7 +1325,7 @@ public static function getFiles(array $dirPatterns, $fileNamePattern, $recursive
13201325 {
13211326 $ result = [];
13221327 foreach ($ dirPatterns as $ oneDirPattern ) {
1323- $ oneDirPattern = str_replace ('\\' , '/ ' , $ oneDirPattern );
1328+ $ oneDirPattern = $ oneDirPattern !== null ? str_replace ('\\' , '/ ' , $ oneDirPattern ) : '' ;
13241329 $ entriesInDir = Glob::glob ("{$ oneDirPattern }/ {$ fileNamePattern }" , Glob::GLOB_NOSORT | Glob::GLOB_BRACE );
13251330 $ subDirs = Glob::glob ("{$ oneDirPattern }/* " , Glob::GLOB_ONLYDIR | Glob::GLOB_NOSORT | Glob::GLOB_BRACE );
13261331 $ filesInDir = array_diff ($ entriesInDir , $ subDirs );
@@ -1389,6 +1394,8 @@ private function getPaths()
13891394 */
13901395 public function classFileExists ($ class , &$ path = '' )
13911396 {
1397+ $ class = $ class ?: '' ;
1398+
13921399 if ($ class [0 ] == '\\' ) {
13931400 $ class = substr ($ class , 1 );
13941401 }
@@ -1459,7 +1466,7 @@ private function classFileExistsCheckContent($fullPath, $namespace, $className)
14591466 * Note that realpath() automatically changes directory separator to the OS-native
14601467 * Since realpath won't work with symlinks we also check file_exists if realpath failed
14611468 */
1462- if (realpath ($ fullPath ) == str_replace (['/ ' , '\\' ], DIRECTORY_SEPARATOR , $ fullPath )
1469+ if ($ fullPath && realpath ($ fullPath ) == str_replace (['/ ' , '\\' ], DIRECTORY_SEPARATOR , $ fullPath )
14631470 || file_exists ($ fullPath )
14641471 ) {
14651472 $ fileContent = file_get_contents ($ fullPath );
@@ -1582,10 +1589,13 @@ public function readLists($globPattern)
15821589 $ result = [];
15831590 $ incorrectPatterns = [];
15841591 foreach ($ patterns as $ pattern ) {
1592+ $ pattern = $ pattern ?? '' ;
1593+
15851594 if (0 === strpos ($ pattern , '# ' )) {
15861595 continue ;
15871596 }
15881597 $ patternParts = explode (' ' , $ pattern );
1598+
15891599 if (count ($ patternParts ) == 3 ) {
15901600 list ($ componentType , $ componentName , $ pathPattern ) = $ patternParts ;
15911601 $ files = $ this ->getPathByComponentPattern ($ componentType , $ componentName , $ pathPattern );
0 commit comments