|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00019 class SimpleCollector { 00020 00026 function _removeTrailingSlash($path) { 00027 if (substr($path, -1) == DIRECTORY_SEPARATOR) { 00028 return substr($path, 0, -1); 00029 } elseif (substr($path, -1) == '/') { 00030 return substr($path, 0, -1); 00031 } else { 00032 return $path; 00033 } 00034 } 00035 00042 function collect(&$test, $path) { 00043 $path = $this->_removeTrailingSlash($path); 00044 if ($handle = opendir($path)) { 00045 while (($entry = readdir($handle)) !== false) { 00046 if ($this->_isHidden($entry)) { 00047 continue; 00048 } 00049 $this->_handle($test, $path . DIRECTORY_SEPARATOR . $entry); 00050 } 00051 closedir($handle); 00052 } 00053 } 00054 00068 function _handle(&$test, $file) { 00069 if (is_dir($file)) { 00070 return; 00071 } 00072 $test->addTestFile($file); 00073 } 00074 00082 function _isHidden($filename) { 00083 return strncmp($filename, '.', 1) == 0; 00084 } 00085 } 00086 00095 class SimplePatternCollector extends SimpleCollector { 00096 var $_pattern; 00097 00104 function SimplePatternCollector($pattern = '/php$/i') { 00105 $this->_pattern = $pattern; 00106 } 00107 00116 function _handle(&$test, $filename) { 00117 if (preg_match($this->_pattern, $filename)) { 00118 parent::_handle($test, $filename); 00119 } 00120 } 00121 } 00122 ?>