C:\xampp2_not used\php\pear\PHP\UML\FileScanner.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/**
 * PHP_UML
 *
 * PHP version 5
 *
 * @category PHP
 * @package  PHP_UML
 * @author   Baptiste Autin <ohlesbeauxjours@yahoo.fr>
 * @license  http://www.gnu.org/licenses/lgpl.html LGPL License 3
 * @version  SVN: $Revision: 105 $
 * @link     http://pear.php.net/package/PHP_UML
 * @link     http://www.baptisteautin.com/projects/PHP_UML/
 * @since    $Date: 2009-06-04 19:48:27 +0200 (jeu., 04 juin 2009) $
 */


/**
 * A superclass for scanning files and folders. It does nothing but browsing
 * recursively the file system tree, given a list of entry folders. At least
 * one folder must be provided.
 * It can be seen as an extension of RecursiveDirectoryIterator, upon which
 * it is based.
 * 
 * @category PHP
 * @package  PHP_UML
 * @author   Baptiste Autin <ohlesbeauxjours@yahoo.fr>
 * @license  http://www.gnu.org/licenses/lgpl.html LGPL License 3
 * 
 */
abstract class PHP_UML_FileScanner
{

    
/**
     * List of directories to scan
     *
     * @var array
     */
    
protected $directories = array();
    
    
/**
     * List of files to scan
     *
     * @var array
     */
    
protected $files = array();
    
    
/**
     * Allowed path-/file-names (possible wildcards are ? and *)
     * 
     * @var array
     */
    
protected $matchPatterns = array('*.php');
    
    
/**
     * Ignored directories (possible wildcards are ? and *)
     *
     * @var array();
     */
    
protected $ignorePatterns = array();


    
/**
     * Constructor
     *
     */
    
public function __construct()
    {
    }

    
/**
     * This function will be called every time the scanner meets
     * a new file (while it looks into the folders), as well as for
     * each file defined in the property $files.
     * It's up to the subclass to define the treatment to be done.
     *
     * @param mixed  $basedir  Directory path
     *
     * @param string $filename File name
     */
    
abstract function tickFile($basedir$filename);

    
/**
     * Starts the scan
     *
     */
    
public function scan()
    {
        
// We parse the directories
        
foreach ($this->directories as $pathItem) {
            
$baseDir  realpath($pathItem);
            
$trailing substr($baseDir, -1);

            if (
$baseDir != false && is_dir($baseDir) && is_readable($baseDir)) {

                if (
$trailing != '/' && $trailing != '\\')
                     
$baseDir .= DIRECTORY_SEPARATOR;
                
                
$objects = new RecursiveIteratorIterator(
                    new 
PHP_UML_FilePatternFilterIterator(
                        new 
RecursiveDirectoryIterator($baseDir), $this->ignorePatterns$this->matchPatterns
                    
)
                );

                
$baseDirPos strlen($baseDir);
                foreach (
$objects as $ptr) {
                    
$relativePath substr($ptr->getPathname(), $baseDirPos);
                    
$this->tickFile($baseDir$relativePath);
                }
            }
            else
                
$this->raiseUnknownFolderException($pathItem);
        }

        
// We parse the files
        
foreach ($this->files as $filenameItem) {
            
$filenameItem realpath($filenameItem);
            
$baseDir      dirname($filenameItem).DIRECTORY_SEPARATOR;
            
$baseName     basename($filenameItem);
            if (
$filenameItem != false)
                
$this->tickFile($baseDir$baseName);
        }

    }

    
/**
     * Can be overriden to treat unknown folder exception
     *
     * @param string $basedir Directory name
     */
    
public function raiseUnknownFolderException($basedir)
    {
    }
    
    public function 
setFiles(array $files)
    {
        
$this->files $files;
    }
    
    public function 
setDirectories(array $directories)
    {
        
$this->directories $directories;
    }
    
    public function 
setMatchPatterns(array $patterns)
    {
        
$this->matchPatterns $patterns;
    }
    
    public function 
setIgnorePatterns(array $patterns)
    {
        
$this->ignorePatterns $patterns;
    }
}
?>
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586