#!/usr/bin/php globr('.', '*.php'); $files = array(); foreach ($raw_files as $file) { $file = substr($file, 2); // rm leading './' if (strncmp('standalone/', $file, 11) === 0) continue; // rm generated files if (substr_count($file, '.') > 1) continue; // rm meta files $ok = true; foreach ($exclude_dirs as $dir) { if (strncmp($dir, $file, strlen($dir)) === 0) { $ok = false; break; } } if (!$ok) continue; // rm excluded directories if (in_array($file, $exclude_files)) continue; // rm excluded files $files[] = $file; } // Reorder list so that dependencies are included first: /** * Returns a lookup array of dependencies for a file. * * @note This function expects that format $name extends $parent on one line * * @param $file * File to check dependencies of. * @return * Lookup array of files the file is dependent on, sorted accordingly. */ function get_dependency_lookup($file) { static $cache = array(); if (isset($cache[$file])) return $cache[$file]; $fh = fopen($file, 'r'); $deps = array(); while (!feof($fh)) { $line = fgets($fh); if (strncmp('HTMLPurifier_ConfigSchema', $line, 25) === 0) { $deps['HTMLPurifier/ConfigSchema.php'] = true; } if (strncmp('class', $line, 5) === 0) { // The implementation here is fragile and will break if we attempt // to use interfaces. Beware! list(, $parent) = explode(' extends ', trim($line, ' {'."\n\r"), 2); if (empty($parent)) break; $dep_file = HTMLPurifier_Bootstrap::getPath($parent); if (!$dep_file) break; $deps[$dep_file] = true; break; } } fclose($fh); foreach (array_keys($deps) as $file) { // Extra dependencies must come *before* base dependencies $deps = get_dependency_lookup($file) + $deps; } $cache[$file] = $deps; return $deps; } /** * Sorts files based on dependencies. This function is lazy and will not * group files with dependencies together; it will merely ensure that a file * is never included before its dependencies are. * * @param $files * Files array to sort. * @return * Sorted array ($files is not modified by reference!) */ function dep_sort($files) { $ret = array(); $cache = array(); foreach ($files as $file) { if (isset($cache[$file])) continue; $deps = get_dependency_lookup($file); foreach (array_keys($deps) as $dep) { if (!isset($cache[$dep])) { $ret[] = $dep; $cache[$dep] = true; } } $cache[$file] = true; $ret[] = $file; } return $ret; } $files = dep_sort($files); // Build the actual include stub: $version = trim(file_get_contents('../VERSION')); $php = "