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
 * This selector just holds one other selector and forwards all
22
 * requests to it. It exists so that there is a single selector
23
 * type that can exist outside of any targets, as an element of
24
 * project. It overrides all of the reference stuff so that it
25
 * works as expected. Note that this is the only selector you
26
 * can reference.
27
 *
28
 * @author  Hans Lellelid <hans@xmpl.org> (Phing)
29
 * @author  Bruce Atherton <bruce@callenish.com> (Ant)
30
 * @package phing.types.selectors
31
 */
32
class SelectSelector extends AndSelector
33
{
34

35
    /**
36
     * @return string
37
     */
38 0
    public function __toString()
39
    {
40 0
        return $this->hasSelectors() ? sprintf('{select: %s}', parent::__toString()) : '';
41
    }
42

43
    /**
44
     * Performs the check for circular references and returns the
45
     * referenced Selector.
46
     */
47 0
    private function getRef()
48
    {
49 0
        return $this->getCheckedRef(get_class($this), "SelectSelector");
50
    }
51

52
    /**
53
     * Indicates whether there are any selectors here.
54
     */
55 0
    public function hasSelectors()
56
    {
57 0
        return $this->isReference() ? $this->getRef()->hasSelectors() : parent::hasSelectors();
58
    }
59

60
    /**
61
     * Gives the count of the number of selectors in this container
62
     */
63 0
    public function count()
64
    {
65 0
        if ($this->isReference()) {
66 0
            return count($this->getRef());
67
        }
68

69 0
        return parent::count();
70
    }
71

72
    /**
73
     * Returns the set of selectors as an array.
74
     *
75
     * @param  Project $p
76
     * @return array
77
     */
78 0
    public function getSelectors(Project $p)
79
    {
80 0
        return $this->isReference() ? $this->getRef()->getSelectors($p) : parent::getSelectors($p);
81
    }
82

83
    /**
84
     * Returns an enumerator for accessing the set of selectors.
85
     */
86 0
    public function selectorElements()
87
    {
88 0
        return $this->isReference() ? $this->getRef()->selectorElements() : parent::selectorElements();
89
    }
90

91
    /**
92
     * Add a new selector into this container.
93
     *
94
     * @param  FileSelector $selector new selector to add
95
     * @return void
96
     * @throws BuildException
97
     */
98 1
    public function appendSelector(FileSelector $selector)
99
    {
100 1
        if ($this->isReference()) {
101 0
            throw $this->noChildrenAllowed();
102
        }
103 1
        parent::appendSelector($selector);
104
    }
105

106
    /**
107
     * Makes sure that there is only one entry, sets an error message if
108
     * not.
109
     */
110 0
    public function verifySettings()
111
    {
112 0
        if ($this->count() != 1) {
113 0
            $this->setError(
114
                "One and only one selector is allowed within the "
115 0
                . "<selector> tag"
116
            );
117
        }
118
    }
119
}

Read our documentation on viewing source code .

Loading