/** * Generates the class manifest - a list of all the PHP files in the * application * * @param string $folder The folder to traverse (recursively) * @param array $classMap The already built class map */ private static function getClassManifest($folder, &$classMap) { $items = scandir($folder); if ($items) { foreach ($items as $item) { // Skip some specific PHP files if (in_array($item, self::$ignore_files)) { continue; } // ignore hidden files and folders if (substr($item, 0, 1) == '.') { continue; } // 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; } // ignore directories with _manifest_exlude file if (@is_dir("{$folder}/{$item}") && file_exists("{$folder}/{$item}/_manifest_exclude")) { continue; } // i18n: ignore language files (loaded on demand) if ($item == 'lang' && @is_dir("{$folder}/{$item}") && ereg_replace("/[^/]+/\\.\\.", "", $folder . '/..') == Director::baseFolder()) { 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 $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]}'.\n\t\t\t\t\t\t\tThis 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]}'.\n\t\t\t\t\t\t\tThis might mean that the wrong code is being used.", E_USER_NOTICE); } } else { $classMap[$itemCode] = "{$folder}/{$item}"; } } } } }