|
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
|
|
|
* A convenience base class that you can subclass Selectors from. It |
|
22
|
|
|
* provides some helpful common behaviour. Note that there is no need |
|
23
|
|
|
* for Selectors to inherit from this class, it is only necessary that |
|
24
|
|
|
* they implement FileSelector. |
|
25
|
|
|
* |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
* |
|
28
|
|
|
* @author <a href="mailto:[email protected]">Bruce Atherton</a> |
|
29
|
|
|
* |
|
30
|
|
|
* @package phing.types.selectors |
|
31
|
|
|
*/ |
|
32
|
|
|
abstract class BaseSelector extends DataType implements FileSelector |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var string $errmsg |
|
36
|
|
|
*/ |
|
37
|
|
|
private $errmsg = null; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var Exception $cause |
|
41
|
|
|
*/ |
|
42
|
|
|
private $cause; |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Allows all selectors to indicate a setup error. Note that only |
|
46
|
|
|
* the first error message is recorded. |
|
47
|
|
|
* |
|
48
|
|
|
* @param string $msg The error message any BuildException should throw. |
|
49
|
|
|
* @param Exception $cause |
|
50
|
|
|
*/ |
|
51
|
4 |
|
public function setError($msg, Exception $cause = null) |
|
52
|
|
|
{ |
|
53
|
4 |
|
if ($this->errmsg === null) { |
|
54
|
4 |
|
$this->errmsg = $msg; |
|
55
|
4 |
|
$this->cause = $cause; |
|
56
|
|
|
} |
|
57
|
4 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Returns any error messages that have been set. |
|
61
|
|
|
* |
|
62
|
|
|
* @return string the error condition |
|
63
|
|
|
*/ |
|
64
|
23 |
|
public function getError() |
|
65
|
|
|
{ |
|
66
|
23 |
|
return $this->errmsg; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* <p>Subclasses can override this method to provide checking of their |
|
71
|
|
|
* state. So long as they call validate() from isSelected(), this will |
|
72
|
|
|
* be called automatically (unless they override validate()).</p> |
|
73
|
|
|
* <p>Implementations should check for incorrect settings and call |
|
74
|
|
|
* setError() as necessary.</p> |
|
75
|
|
|
* |
|
76
|
|
|
* @throws \BuildException |
|
77
|
|
|
*/ |
|
78
|
|
|
public function verifySettings() |
|
79
|
|
|
{ |
|
80
|
|
|
if ($this->isReference()) { |
|
81
|
|
|
$this->getCheckedRef(__CLASS__, StringHelper::unqualify(__CLASS__))->verifySettings(); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* Subclasses can use this to throw the requisite exception |
|
87
|
|
|
* in isSelected() in the case of an error condition. |
|
88
|
|
|
* |
|
89
|
|
|
* @throws BuildException |
|
90
|
|
|
*/ |
|
91
|
23 |
|
public function validate() |
|
92
|
|
|
{ |
|
93
|
23 |
|
if ($this->getError() === null) { |
|
|
|
|
|
|
94
|
21 |
|
$this->verifySettings(); |
|
95
|
|
|
} |
|
96
|
23 |
|
if ($this->getError() !== null) { |
|
|
|
|
|
|
97
|
4 |
|
throw new BuildException($this->errmsg, $this->cause); |
|
98
|
|
|
} |
|
99
|
19 |
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|