phingofficial /
phing
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
||
| 5 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
||
| 6 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
||
| 7 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
||
| 8 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
||
| 9 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
||
| 10 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
||
| 11 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
||
| 12 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
||
| 13 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
||
| 14 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 15 | * |
||
| 16 | * This software consists of voluntary contributions made by many individuals |
||
| 17 | * and is licensed under the LGPL. For more information please see |
||
| 18 | * <http://phing.info>. |
||
| 19 | */ |
||
| 20 | |||
| 21 | namespace Phing; |
||
| 22 | |||
| 23 | use Exception; |
||
| 24 | use Phing\Exception\BuildException; |
||
| 25 | use Phing\Parser\ProjectConfigurator; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Wrapper class that holds the attributes of a Task (or elements |
||
| 29 | * nested below that level) and takes care of configuring that element |
||
| 30 | * at runtime. |
||
| 31 | * |
||
| 32 | * <strong>SMART-UP INLINE DOCS</strong> |
||
| 33 | * |
||
| 34 | * @author Andreas Aderhold <[email protected]> |
||
| 35 | * @author Hans Lellelid <[email protected]> |
||
| 36 | */ |
||
| 37 | class RuntimeConfigurable |
||
| 38 | { |
||
| 39 | private $elementTag; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var array |
||
| 43 | */ |
||
| 44 | private $children = []; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var object|Task |
||
| 48 | */ |
||
| 49 | private $wrappedObject; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var array |
||
| 53 | */ |
||
| 54 | private $attributes = []; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | private $characters = ''; |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @var bool |
||
| 63 | */ |
||
| 64 | private $proxyConfigured = false; |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @param object|Task $proxy |
||
| 68 | * @param mixed $elementTag the element to wrap |
||
| 69 | */ |
||
| 70 | 903 | public function __construct($proxy, $elementTag) |
|
| 71 | { |
||
| 72 | 903 | $this->wrappedObject = $proxy; |
|
| 73 | 903 | $this->elementTag = $elementTag; |
|
| 74 | |||
| 75 | 903 | if ($proxy instanceof Task) { |
|
| 76 | 902 | $proxy->setRuntimeConfigurableWrapper($this); |
|
| 77 | } |
||
| 78 | } |
||
| 79 | |||
| 80 | /** |
||
| 81 | * @return object|Task |
||
| 82 | */ |
||
| 83 | 569 | public function getProxy() |
|
| 84 | { |
||
| 85 | 569 | return $this->wrappedObject; |
|
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * @param object|Task $proxy |
||
| 90 | */ |
||
| 91 | 768 | public function setProxy($proxy) |
|
| 92 | { |
||
| 93 | 768 | $this->wrappedObject = $proxy; |
|
| 94 | 768 | $this->proxyConfigured = false; |
|
| 95 | } |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Set's the attributes for the wrapped element. |
||
| 99 | * |
||
| 100 | * @param array $attributes |
||
| 101 | */ |
||
| 102 | 902 | public function setAttributes($attributes) |
|
| 103 | { |
||
| 104 | 902 | $this->attributes = $attributes; |
|
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Returns the AttributeList of the wrapped element. |
||
| 109 | * |
||
| 110 | * @return array |
||
| 111 | */ |
||
| 112 | public function getAttributes() |
||
| 113 | { |
||
| 114 | return $this->attributes; |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Adds child elements to the wrapped element. |
||
| 119 | */ |
||
| 120 | 569 | public function addChild(RuntimeConfigurable $child) |
|
| 121 | { |
||
| 122 | 569 | $this->children[] = $child; |
|
| 123 | } |
||
| 124 | |||
| 125 | /** |
||
| 126 | * Returns the child with index. |
||
| 127 | * |
||
| 128 | * @param int $index |
||
| 129 | * |
||
| 130 | * @return RuntimeConfigurable |
||
| 131 | */ |
||
| 132 | 475 | public function getChild($index) |
|
| 133 | { |
||
| 134 | 475 | return $this->children[(int) $index]; |
|
| 135 | } |
||
| 136 | |||
| 137 | public function getChildren() |
||
| 138 | { |
||
| 139 | return $this->children; |
||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Add characters from #PCDATA areas to the wrapped element. |
||
| 144 | * |
||
| 145 | * @param string $data |
||
| 146 | */ |
||
| 147 | 773 | public function addText($data) |
|
| 148 | { |
||
| 149 | 773 | $this->characters .= (string) $data; |
|
| 150 | } |
||
| 151 | |||
| 152 | /** |
||
| 153 | * Get the text content of this element. Various text chunks are |
||
| 154 | * concatenated, there is no way (currently) of keeping track of |
||
| 155 | * multiple fragments. |
||
| 156 | * |
||
| 157 | * @return string the text content of this element |
||
| 158 | */ |
||
| 159 | 5 | public function getText() |
|
| 160 | { |
||
| 161 | 5 | return (string) $this->characters; |
|
| 162 | } |
||
| 163 | |||
| 164 | public function getElementTag() |
||
| 165 | { |
||
| 166 | return $this->elementTag; |
||
| 167 | } |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Reconfigure the element, even if it has already been configured. |
||
| 171 | * |
||
| 172 | * @param Project $p the project instance for this configuration |
||
| 173 | */ |
||
| 174 | public function reconfigure(Project $p) |
||
| 175 | { |
||
| 176 | $this->proxyConfigured = false; |
||
| 177 | $this->maybeConfigure($p); |
||
| 178 | } |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Configure the wrapped element and all children. |
||
| 182 | * |
||
| 183 | * @throws BuildException |
||
| 184 | * @throws Exception |
||
| 185 | */ |
||
| 186 | 769 | public function maybeConfigure(Project $project) |
|
| 187 | { |
||
| 188 | 769 | if ($this->proxyConfigured) { |
|
| 189 | 7 | return; |
|
| 190 | } |
||
| 191 | |||
| 192 | 769 | $id = null; |
|
| 193 | |||
| 194 | 769 | if ($this->attributes || (isset($this->characters) && '' !== $this->characters)) { |
|
|
0 ignored issues
–
show
|
|||
| 195 | 763 | ProjectConfigurator::configure($this->wrappedObject, $this->attributes, $project); |
|
| 196 | |||
| 197 | 763 | if (isset($this->attributes['id'])) { |
|
| 198 | 84 | $id = $this->attributes['id']; |
|
| 199 | } |
||
| 200 | |||
| 201 | 763 | if ('' !== $this->characters) { |
|
| 202 | 523 | ProjectConfigurator::addText($project, $this->wrappedObject, $this->characters); |
|
| 203 | } |
||
| 204 | 763 | if (null !== $id) { |
|
| 205 | 84 | $project->addReference($id, $this->wrappedObject); |
|
| 206 | } |
||
| 207 | } |
||
| 208 | |||
| 209 | 769 | $this->proxyConfigured = true; |
|
| 210 | } |
||
| 211 | |||
| 212 | 5 | public function setAttribute(string $name, $value) |
|
| 213 | { |
||
| 214 | 5 | $this->attributes[$name] = $value; |
|
| 215 | } |
||
| 216 | |||
| 217 | 5 | public function removeAttribute(string $name) |
|
| 218 | { |
||
| 219 | 5 | unset($this->attributes[$name]); |
|
| 220 | } |
||
| 221 | |||
| 222 | 5 | public function setElementTag(string $name) |
|
| 223 | { |
||
| 224 | 5 | $this->elementTag = $name; |
|
| 225 | } |
||
| 226 | |||
| 227 | 763 | public function getId() |
|
| 228 | { |
||
| 229 | 763 | return $this->attributes['id'] ?? null; |
|
| 230 | } |
||
| 231 | } |
||
| 232 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.