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
 * @author    Siad Ardroumli <siad.ardroumli@gmail.com>
22
 * @package   phing.tasks.ext.property
23
 */
24
class URLEncodeTask extends AbstractPropertySetterTask
25
{
26
    /**
27
     * @var string
28
     */
29
    private $value = '';
30

31
    /**
32
     * @var Reference
33
     */
34
    private $ref;
35

36 1
    public function setValue(string $value)
37
    {
38 1
        $this->value = urlencode($value);
39
    }
40

41 1
    public function getValue(Project $p): string
42
    {
43 1
        if ($this->ref !== null) {
44 1
            $this->setValue($this->ref->getReferencedObject($p));
45
        }
46

47 1
        return $this->value;
48
    }
49

50 1
    public function setRefid(Reference $ref)
51
    {
52 1
        $this->ref = $ref;
53
    }
54

55 0
    public function __toString()
56
    {
57 0
        return $this->value;
58
    }
59

60 0
    protected function validate()
61
    {
62 0
        parent::validate();
63 0
        if ($this->value === null && $this->ref === null) {
64 0
            throw new BuildException(
65 0
                'You must specify value or refid with the name attribute',
66 0
                $this->getLocation()
67
            );
68
        }
69
    }
70

71 1
    public function main()
72
    {
73 1
        parent::validate();
74 1
        $val = $this->getValue($this->getProject());
75 1
        $this->setPropertyValue($val);
76
    }
77
}

Read our documentation on viewing source code .

Loading