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
 * Abstract Service_Amazon class.
22
 *
23
 * Implements common methods & properties used by all Amazon services
24
 *
25
 * @extends  Task
26
 * @version  $ID$
27
 * @package  phing.tasks.ext
28
 * @author   Andrei Serdeliuc <andrei@serdeliuc.ro>
29
 * @abstract
30
 */
31
abstract class Amazon extends Task
32
{
33
    /**
34
     * Collection of set options
35
     *
36
     * We set these magically so we can also load then from the environment
37
     *
38
     * (default value: array())
39
     *
40
     * @var array
41
     */
42
    protected $options = [];
43

44
    /**
45
     * @param string $var
46
     * @param mixed $val
47
     */
48 0
    public function __set($var, $val)
49
    {
50 0
        $this->options[$var] = $val;
51
    }
52

53
    /**
54
     * Property getter
55
     *
56
     * If the property hasn't been previously set (through the task call normally),
57
     * it will try to load it from the project
58
     *
59
     * This way, we can define global properties for the "Amazon" service, like key and secret
60
     *
61
     * @param  mixed $var
62
     * @return mixed
63
     */
64 0
    public function __get($var)
65
    {
66 0
        if (!isset($this->$var)) {
67 0
            if (!($val = $this->getProject()->getProperty('amazon.' . strtolower($var)))) {
68 0
                return false;
69
            }
70

71 0
            return $val;
72
        }
73

74 0
        return $this->options[$var];
75
    }
76

77
    /**
78
     * @param string $var
79
     * @return bool
80
     */
81 0
    public function __isset($var)
82
    {
83 0
        return array_key_exists($var, $this->options);
84
    }
85

86
    /**
87
     * @param string $key
88
     * @throws BuildException if $key is an empty string
89
     */
90 0
    public function setKey($key)
91
    {
92 0
        if (empty($key) || !is_string($key)) {
93 0
            throw new BuildException('Key must be a non empty string');
94
        }
95

96 0
        $this->key = $key;
97
    }
98

99
    /**
100
     * @return string
101
     *
102
     * @throws BuildException if key is not set
103
     */
104 0
    public function getKey()
105
    {
106 0
        if (!($key = $this->key)) {
107 0
            throw new BuildException('Key is not set');
108
        }
109

110 0
        return $key;
111
    }
112

113
    /**
114
     * @param string $secret
115
     * @throws BuildException if $secret is a empty string
116
     */
117 0
    public function setSecret($secret)
118
    {
119 0
        if (empty($secret) || !is_string($secret)) {
120 0
            throw new BuildException('Secret must be a non empty string');
121
        }
122

123 0
        $this->secret = $secret;
124
    }
125

126
    /**
127
     * @return string
128
     *
129
     * @throws BuildException if secret is not set
130
     */
131 0
    public function getSecret()
132
    {
133 0
        if (!($secret = $this->secret)) {
134 0
            throw new BuildException('Secret is not set');
135
        }
136

137 0
        return $this->secret;
138
    }
139
}

Read our documentation on viewing source code .

Loading