1
<?php
2
/**
3
 * Part of phing, the PHP build tool
4
 *
5
 * PHP version 5
6
 *
7
 * @category Types
8
 * @package  phing.types
9
 * @author   Christian Weiske <cweiske@cweiske.de>
10
 * @license  LGPL v3 or later http://www.gnu.org/licenses/lgpl.html
11
 * @link     http://www.phing.info/
12
 */
13

14
/**
15
 * Fileset that contains files of an installed PEAR package.
16
 * It can be used to package up PEAR package dependencies in own
17
 * release files (zip, tgz, phar).
18
 *
19
 * @internal
20
 * A normal fileset is used that way in CopyTask, RSTTask:
21
 * <code>
22
 *  $ds = $fs->getDirectoryScanner($project);
23
 *  $fromDir  = $fs->getDir($project);
24
 *  $srcFiles = $ds->getIncludedFiles();
25
 *  $srcDirs  = $ds->getIncludedDirectories();
26
 * </code>
27
 * The scanner is used as follows:
28
 * <code>
29
 *  $ds->getBaseDir()
30
 *  $ds->scan()
31
 * </code>
32
 *
33
 * @category Types
34
 * @package  phing.types
35
 * @author   Christian Weiske <cweiske@cweiske.de>
36
 * @license  LGPL v3 or later http://www.gnu.org/licenses/lgpl.html
37
 * @link     http://www.phing.info/
38
 */
39
class PearPackageFileSet extends FileSet
40
{
41
    /**
42
     * Name of channel the package is from, e.g. "pear.php.net".
43
     *
44
     * @var string
45
     */
46
    protected $channel;
47

48
    /**
49
     * Package name to get files from, e.g. "Console_CommandLine"
50
     *
51
     * @var string
52
     */
53
    protected $package;
54

55
    /**
56
     * File to use for generated package.xml
57
     *
58
     * @var string
59
     */
60
    protected $packageFile = '';
61

62
    /**
63
     * Use files of that role only.
64
     * Multiple roles are not supported, and you always have to specify one.
65
     *
66
     * @var string
67
     */
68
    protected $role = 'php';
69

70
    /**
71
     * Full path to a PEAR config file.
72
     * If none provided, default one is used.
73
     *
74
     * @var string
75
     */
76
    protected $config;
77

78
    /**
79
     * @var PearPackageScanner instance
80
     */
81
    protected $pps;
82

83
    /**
84
     * Creates and returns the pear package scanner.
85
     * Scanner already has scan() called.
86
     *
87
     * @param Project $p Current phing project
88
     *
89
     * @return PearPackageScanner
90
     */
91 0
    public function getDirectoryScanner(Project $p = null)
92
    {
93 0
        if ($p === null) {
94 0
            $p = $this->getProject();
95
        }
96 0
        if ($this->isReference()) {
97 0
            $obj = $this->getRef($p);
98

99 0
            return $obj->getDirectoryScanner($p);
100
        }
101

102 0
        $this->loadPearPackageScanner($p);
103

104 0
        return $this->pps;
105
    }
106

107
    /**
108
     * Returns the base directory all package files are relative to
109
     *
110
     * @param Project $p Current phing project
111
     *
112
     * @return PhingFile Base directory
113
     */
114 0
    public function getDir(Project $p = null)
115
    {
116 0
        if ($p === null) {
117 0
            $p = $this->getProject();
118
        }
119 0
        if ($this->pps === null) {
120 0
            $this->loadPearPackageScanner($p);
121
        }
122

123 0
        return new PhingFile((string) $this->pps->getBaseDir());
124
    }
125

126
    /**
127
     * Loads the package scanner instance into $this->pps
128
     *
129
     * @param Project $p Current phing project
130
     *
131
     * @return void
132
     */
133 0
    protected function loadPearPackageScanner(Project $p)
134
    {
135 0
        $this->pps = new PearPackageScanner();
136 0
        $this->pps->setDescFile($this->packageFile);
137 0
        $this->pps->setPackage($this->package);
138 0
        $this->pps->setChannel($this->channel);
139 0
        $this->pps->setRole($this->role);
140 0
        $this->pps->setConfig($this->config);
141 0
        $this->pps->setIncludes($this->defaultPatterns->getIncludePatterns($p));
142 0
        $this->pps->setExcludes($this->defaultPatterns->getExcludePatterns($p));
143 0
        $this->pps->scan();
144
    }
145

146
    /**
147
     * Sets the package.xml filename.
148
     * If it is not set, the local pear installation is queried for the package.
149
     *
150
     * @param  $descFile
151
     * @return void
152
     */
153 0
    public function setDescFile($descFile)
154
    {
155 0
        $this->packageFile = $descFile;
156
    }
157

158
    /**
159
     * Sets the package name.
160
     * If no channel is given, "pear.php.net" is used.
161
     *
162
     * @param string $package Single package name, or "channel/name" combination
163
     *
164
     * @throws BuildException
165
     * @return void
166
     */
167 0
    public function setPackage($package)
168
    {
169 0
        $parts = explode('/', $package);
170 0
        if (count($parts) > 2) {
171 0
            throw new BuildException('Invalid package name: ' . $package);
172
        }
173

174 0
        if (count($parts) == 1) {
175 0
            $this->channel = 'pear.php.net';
176 0
            $this->package = $parts[0];
177
        } else {
178 0
            $this->channel = $parts[0];
179 0
            $this->package = $parts[1];
180
        }
181
    }
182

183
    /**
184
     * Sets the role of files that should be included.
185
     * Examples are php,doc,script
186
     *
187
     * @param string $role PEAR file role
188
     *
189
     * @return void
190
     */
191 0
    public function setRole($role)
192
    {
193 0
        $this->role = $role;
194
    }
195

196
    /**
197
     * Sets the full path to the PEAR configuration file
198
     *
199
     * @param string $config Configuration file
200
     *
201
     * @return void
202
     */
203 0
    public function setConfig($config)
204
    {
205 0
        $this->config = $config;
206
    }
207
}

Read our documentation on viewing source code .

Loading