PEAR2_Pyrus_Developer-0.2.0PEAR2_Pyrus_Developer-0.2.0/php/pear2/Pyrus/Developer/PackageFile/PEAR2SVN/Filter.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
namespace pear2\Pyrus\Developer\PackageFile\PEAR2SVN;
class Filter extends \FilterIterator
{
    protected $path;
    protected $role;
    function __construct($path, $it, $role)
    {
        $this->path = $path;
        $this->role = $role;
        parent::__construct($it);
    }

    public function accept()
    {
        if ($this->getInnerIterator()->isDot()) {
            return false;
        }
    
        $path = str_replace('\\', '/', $this->path);
        $path = str_replace($path, '', $this->getInnerIterator()->current()->getPathName());
        if ($path && $path[0] === DIRECTORY_SEPARATOR) {
            $path = substr($path, 1);
        }
        
        if (preg_match('@/?\.svn/@', $path)) {
            return false;
        }
        
        switch($this->role) {
        case 'test':
            return $this->filterTestsDir();
        }
        return true;
    }
    
    function filterTestsDir()
    {
        if ($this->getInnerIterator()->current()->getBasename() == 'pear2coverage.db') {
            return false;
        }
        $invalid_extensions = array('diff','exp','log','out', 'xdebug');
        $info = pathinfo($this->getInnerIterator()->current()->getPathName());
        if (!isset($info['extension'])) {
            return true;
        }
        if ($info['extension'] == 'php'
            && file_exists($info['dirname'].DIRECTORY_SEPARATOR.$info['filename'].'.phpt')) {
            // Assume this is the result of a failed .phpt test
            return false;
        }
        return !in_array($info['extension'], $invalid_extensions);
    }
}
EOF