+ // skip non-php files
+ if (substr($f, -4) != '.php') {
+ continue;
+ }
+
+ // subdir inside php_pear_dir
+ if (substr($f, 0, $length) == $prefix) {
+ $file_dir = dirname(substr($f, $length));
+ } else {
+ $file_dir = null;
+ }
+
+ foreach (file($f) as $line) {
+ // skip comments -- not perfect, matches "*" at start of line (very rare altho)
+ if (preg_match('/^\s*(#|\/\/|\*|\/\*)/', $line)) {
+ continue;
+ }
+
+ if (preg_match("/(\W|^)(require|include)(_once)?
+ \s* \(? \s*
+ (\"([^\"]*)\"|'([^']*)')
+ \s* \)? \s* ;/x", $line, $m)) {
+
+ if ($m[5]) {
+ $x = $m[5];
+ } else if ($m[6]) {
+ $x = $m[6];
+ } else {
+ continue 2;
+ }
+
+ if (substr($x, 0, 2) == './' || substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR
+ continue 2;
+ }
+
+ if (substr($x, -4) != '.php') {
+ continue 2;
+ }
+ $req[$x] = 1;
+ continue 2;
+ }
+
+ if (is_null($file_dir)) {
+ continue;
+ }
+
+ if (preg_match("/(\W|^)(require|include)(_once)?
+ \s* \(? \s* dirname \s* \( \s* __FILE__ \s* \) \s* \. \s*
+ (\"([^\"]*)\"|'([^']*)')
+ \s* \)? \s* ;/x", $line, $m)) {
+
+ if ($m[5]) {
+ $x = $m[5];
+ } else if ($m[6]) {
+ $x = $m[6];
+ } else {
+ continue 2;
+ }
+
+ if (substr($x, -1) == '$') { # XXX must be: CONTAINS DOLLAR
+ continue 2;
+ }
+ if (substr($x, -4) != '.php') {
+ continue 2;
+ }
+
+ $x = "$file_dir/$x";
+ // remove double slashes
+ // TODO: resolve simpletest/test/../socket.php -> simpletest/socket.php
+ $x = str_replace("//", "/", $x);
+ $req[$x] = 1;
+ continue;
+ }
+ }
+ }
+
+ foreach (array_keys($req) as $f) {
+ // skip self deps
+ if (array_key_exists($f, $files)) {