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
 * Represents a slot in the register.
22
 *
23
 * @package phing.system.util
24
 */
25
class RegisterSlot
26
{
27

28
    /**
29
     * The name of this slot.
30
     */
31
    private $key;
32

33
    /**
34
     * The value for this slot.
35
     */
36
    private $value;
37

38
    /**
39
     * Constructs a new RegisterSlot, setting the key to passed param.
40
     *
41
     * @param string $key
42
     */
43 1
    public function __construct($key)
44
    {
45 1
        $this->key = (string) $key;
46
    }
47

48
    /**
49
     * Sets the key / name for this slot.
50
     *
51
     * @param string $k
52
     */
53 0
    public function setKey($k)
54
    {
55 0
        $this->key = (string) $k;
56
    }
57

58
    /**
59
     * Gets the key / name for this slot.
60
     *
61
     * @return string
62
     */
63 0
    public function getKey()
64
    {
65 0
        return $this->key;
66
    }
67

68
    /**
69
     * Sets the value for this slot.
70
     *
71
     * @param mixed
72
     */
73 1
    public function setValue($v)
74
    {
75 1
        $this->value = $v;
76
    }
77

78
    /**
79
     * Returns the value at this slot.
80
     *
81
     * @return mixed
82
     */
83 1
    public function getValue()
84
    {
85 1
        return $this->value;
86
    }
87

88
    /**
89
     * Recursively implodes an array to a comma-separated string
90
     *
91
     * @param  array $arr
92
     * @return string
93
     */
94 1
    private function implodeArray(array $arr)
95
    {
96 1
        $values = [];
97

98 1
        foreach ($arr as $value) {
99 1
            if (is_array($value)) {
100 1
                $values[] = $this->implodeArray($value);
101
            } else {
102 1
                $values[] = $value;
103
            }
104
        }
105

106 1
        return "{" . implode(",", $values) . "}";
107
    }
108

109
    /**
110
     * Returns the value at this slot as a string value.
111
     *
112
     * @return string
113
     */
114 1
    public function __toString()
115
    {
116 1
        if (is_array($this->value)) {
117 1
            return $this->implodeArray($this->value);
118
        }
119

120 1
        return (string) $this->value;
121
    }
122
}

Read our documentation on viewing source code .

Loading