From 0eada9f41b012f1efd3a931808a61deb80ac4e3f Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Fri, 14 Sep 2007 23:03:29 +0000 Subject: [PATCH] Refactored getClassManifest() for clearer ignore-rules added $ignore_files and $ignore_folders git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@41810 467b73ca-7a2a-4603-9d3b-597d59a354a9 --- core/ManifestBuilder.php | 66 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 61 insertions(+), 5 deletions(-) diff --git a/core/ManifestBuilder.php b/core/ManifestBuilder.php index a9817f4e9..708543a66 100644 --- a/core/ManifestBuilder.php +++ b/core/ManifestBuilder.php @@ -17,6 +17,30 @@ class ManifestBuilder { static $restrict_to_modules = array(); + /** + * @var array $ignore_files Full filenames (without directory-path) which + * should be ignored by the manifest. + */ + public static $ignore_files = array( + 'main.php', + 'cli-script.php', + 'install.php', + 'index.php', + 'check-php.php', + 'rewritetest.php' + ); + + /** + * @var array $ignore_folders Foldernames (without path) which + * should be ignored by the manifest. + */ + public static $ignore_folders = array( + 'mysql', + 'assets', + 'shortstat', + 'pear', + ); + /** * Returns true if the manifest file should be regenerated */ @@ -146,13 +170,45 @@ class ManifestBuilder { private static function getClassManifest($folder, &$classMap) { $items = scandir($folder); if($items) foreach($items as $item) { - if($item == 'main.php' || $item == 'cli-script.php' || $item == 'install.php' || $item == 'index.php' || $item == 'check-php.php' || $item == 'rewritetest.php') continue; + // ignore files such as index.php + if(in_array($item, self::$ignore_files)) continue; + + // ignore hidden files and folders if(substr($item,0,1) == '.') continue; - if(substr($item,-4) == '.php' && substr($item,0,1) != '_') { + + // ignore files without php-extension + if(substr($item,-4) != '.php' && !is_dir("$folder/$item")) continue; + + // ignore files and folders with underscore-prefix + if(substr($item,0,1) == '_') continue; + + // ignore certain directories + if(is_dir("$folder/$item") && in_array($item, self::$ignore_folders)) continue; + + if(is_dir("$folder/$item")) { + // recurse into directories (if not in $ignore_folders) + ManifestBuilder::getClassManifest("$folder/$item", $classMap); + } else { + // include item in the manifest $itemCode = substr($item,0,-4); - if($classMap && array_key_exists($itemCode, $classMap)) user_error("Warning: there are two '$itemCode' files: '$folder/$item' and '{$classMap[$itemCode]}'. This might mean that the wrong code is being used.", E_USER_WARNING); - $classMap[$itemCode] = "$folder/$item"; - } else if(is_dir("$folder/$item") && !in_array($item, array('mysql', 'assets', 'shortstat', 'pear'))) ManifestBuilder::getClassManifest("$folder/$item", $classMap); + // if $itemCode is already in manifest, check if the two files do really contain the same class + if($classMap && array_key_exists($itemCode, $classMap)) { + $regex = '/class\s' . $itemCode .'/'; + if( + preg_match($regex, file_get_contents("$folder/$item")) + && preg_match($regex, file_get_contents($classMap[$itemCode])) + ) { + user_error("Warning: there are two '$itemCode' files both containing the same class: '$folder/$item' and '{$classMap[$itemCode]}'. + This might mean that the wrong code is being used.", E_USER_WARNING); + } else { + user_error("Warning: there are two '$itemCode' files with the same filename: '$folder/$item' and '{$classMap[$itemCode]}'. + This might mean that the wrong code is being used.", E_USER_WARNING); + } + } else { + $classMap[$itemCode] = "$folder/$item"; + } + } + } }