123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
-
-
-
- class SimpleCollector {
-
-
-
- protected function removeTrailingSlash($path) {
- if (substr($path, -1) == DIRECTORY_SEPARATOR) {
- return substr($path, 0, -1);
- } elseif (substr($path, -1) == '/') {
- return substr($path, 0, -1);
- } else {
- return $path;
- }
- }
-
-
-
- function collect(&$test, $path) {
- $path = $this->removeTrailingSlash($path);
- if ($handle = opendir($path)) {
- while (($entry = readdir($handle)) !== false) {
- if ($this->isHidden($entry)) {
- continue;
- }
- $this->handle($test, $path . DIRECTORY_SEPARATOR . $entry);
- }
- closedir($handle);
- }
- }
-
-
-
- protected function handle(&$test, $file) {
- if (is_dir($file)) {
- return;
- }
- $test->addFile($file);
- }
-
-
-
- protected function isHidden($filename) {
- return strncmp($filename, '.', 1) == 0;
- }
- }
-
-
- class SimplePatternCollector extends SimpleCollector {
- private $pattern;
-
-
-
- function __construct($pattern = '/php$/i') {
- $this->pattern = $pattern;
- }
-
-
-
- protected function handle(&$test, $filename) {
- if (preg_match($this->pattern, $filename)) {
- parent::handle($test, $filename);
- }
- }
- }
- ?>
|