1
<?php
2
/**
3
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the LGPL. For more information please see
17
 * <http://phing.info>.
18
 */
19

20
/**
21
 * Datatype which handles excluded files, classes and methods.
22
 *
23
 * @package phing.types
24
 * @author  Benjamin Schultz <bschultz@proqrent.de>
25
 * @since   2.4.6
26
 */
27
class Excludes extends DataType
28
{
29
    /**
30
     * The directory scanner for getting the excluded files
31
     *
32
     * @var DirectoryScanner
33
     */
34
    private $directoryScanner = null;
35

36
    /**
37
     * Holds the excluded file patterns
38
     *
39
     * @var ExcludesNameEntry[]
40
     */
41
    private $files = [];
42

43
    /**
44
     * Holds the excluded classes
45
     *
46
     * @var ExcludesNameEntry[]
47
     */
48
    private $classes = [];
49

50
    /**
51
     * Holds the excluded methods
52
     *
53
     * @var ExcludesNameEntry[]
54
     */
55
    private $methods = [];
56

57
    /**
58
     * @param Project $project
59
     */
60 0
    public function __construct(Project $project)
61
    {
62 0
        parent::__construct();
63 0
        $this->directoryScanner = new DirectoryScanner();
64 0
        $this->directoryScanner->setBasedir($project->getBasedir());
65
    }
66

67
    /**
68
     * Add a name entry on the exclude file list
69
     *
70
     * @return ExcludesNameEntry Reference to object
71
     */
72 0
    public function createFile()
73
    {
74 0
        return $this->addExcludesNameEntry($this->files);
75
    }
76

77
    /**
78
     * Add a name entry on the exclude class list
79
     *
80
     * @return ExcludesNameEntry Reference to object
81
     */
82 0
    public function createClass()
83
    {
84 0
        return $this->addExcludesNameEntry($this->classes);
85
    }
86

87
    /**
88
     * Add a name entry on the exclude method list
89
     *
90
     * @return ExcludesNameEntry Reference to object
91
     */
92 0
    public function createMethod()
93
    {
94 0
        return $this->addExcludesNameEntry($this->methods);
95
    }
96

97
    /**
98
     * Adds a new ExcludesNameEntry to the given exclusion list.
99
     *
100
     * @param ExcludesNameEntry[] $excludesNameEntryList
101
     *
102
     * @return ExcludesNameEntry Reference to the created ExcludesNameEntry instance
103
     */
104 0
    private function addExcludesNameEntry(&$excludesNameEntryList)
105
    {
106 0
        $excludesNameEntry = new ExcludesNameEntry();
107 0
        $excludesNameEntryList[] = $excludesNameEntry;
108

109 0
        return $excludesNameEntry;
110
    }
111

112
    /**
113
     * Returns the excluded files
114
     *
115
     * @return array
116
     */
117 0
    public function getExcludedFiles()
118
    {
119 0
        $includes = [];
120

121 0
        foreach ($this->files as $file) {
122 0
            $includes[] = $file->getName();
123
        }
124

125 0
        $this->directoryScanner->setIncludes($includes);
126 0
        $this->directoryScanner->scan();
127

128 0
        $files = $this->directoryScanner->getIncludedFiles();
129 0
        $dir = $this->directoryScanner->getBasedir();
130 0
        $fileList = [];
131

132 0
        foreach ($files as $file) {
133 0
            $fileList[] = $dir . DIRECTORY_SEPARATOR . $file;
134
        }
135

136 0
        return $fileList;
137
    }
138

139
    /**
140
     * Returns the excluded class names
141
     *
142
     * @return array
143
     */
144 0
    public function getExcludedClasses()
145
    {
146 0
        $excludedClasses = [];
147

148 0
        foreach ($this->classes as $excludedClass) {
149 0
            $excludedClasses[] = $excludedClass->getName();
150
        }
151

152 0
        return $excludedClasses;
153
    }
154

155
    /**
156
     * Returns the excluded method names
157
     *
158
     * @return array
159
     */
160 0
    public function getExcludedMethods()
161
    {
162 0
        $excludedMethods = [];
163

164 0
        foreach ($this->methods as $excludedMethod) {
165 0
            $classAndMethod = explode('::', $excludedMethod->getName());
166 0
            $className = $classAndMethod[0];
167 0
            $methodName = $classAndMethod[1];
168

169 0
            $excludedMethods[$className][] = $methodName;
170
        }
171

172 0
        return $excludedMethods;
173
    }
174
}

Read our documentation on viewing source code .

Loading