| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* Copyright 2010-2012 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
|
4 |
*
|
|
|
5 |
* Licensed under the Apache License, Version 2.0 (the "License").
|
|
|
6 |
* You may not use this file except in compliance with the License.
|
|
|
7 |
* A copy of the License is located at
|
|
|
8 |
*
|
|
|
9 |
* http://aws.amazon.com/apache2.0
|
|
|
10 |
*
|
|
|
11 |
* or in the "license" file accompanying this file. This file is distributed
|
|
|
12 |
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
|
|
|
13 |
* express or implied. See the License for the specific language governing
|
|
|
14 |
* permissions and limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
/*%******************************************************************************************%*/
|
|
|
19 |
// CLASS
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* The <CFCredential> class represents an individual credential set.
|
|
|
23 |
*
|
|
|
24 |
* @version 2011.11.15
|
|
|
25 |
* @license See the included NOTICE.md file for more information.
|
|
|
26 |
* @copyright See the included NOTICE.md file for more information.
|
|
|
27 |
* @link http://aws.amazon.com/php/ PHP Developer Center
|
|
|
28 |
*/
|
|
|
29 |
class CFCredential implements ArrayAccess
|
|
|
30 |
{
|
|
|
31 |
/**
|
|
|
32 |
* Stores the internal <php:ArrayObject> representation of the collection.
|
|
|
33 |
*/
|
|
|
34 |
private $collection;
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Default getter. Enables syntax such as $object->method->chained_method();. Also supports
|
|
|
38 |
* $object->key. Matching methods are prioritized over matching keys.
|
|
|
39 |
*
|
|
|
40 |
* @param string $name (Required) The name of the method to execute or key to retrieve.
|
|
|
41 |
* @return mixed The results of calling the function <code>$name()</code>, or the value of the key <code>$object[$name]</code>.
|
|
|
42 |
*/
|
|
|
43 |
public function __get($name)
|
|
|
44 |
{
|
|
|
45 |
return $this[$name];
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* Default setter.
|
|
|
50 |
*
|
|
|
51 |
* @param string $name (Required) The name of the method to execute.
|
|
|
52 |
* @param string $value (Required) The value to pass to the method.
|
|
|
53 |
* @return mixed The results of calling the function, <code>$name</code>.
|
|
|
54 |
*/
|
|
|
55 |
public function __set($name, $value)
|
|
|
56 |
{
|
|
|
57 |
$this[$name] = $value;
|
|
|
58 |
return $this;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
/**
|
|
|
62 |
* Create a clone of the object.
|
|
|
63 |
*
|
|
|
64 |
* @return CFCredential A clone of the current instance.
|
|
|
65 |
*/
|
|
|
66 |
public function __clone()
|
|
|
67 |
{
|
|
|
68 |
$this->collection = clone $this->collection;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
|
|
|
72 |
/*%******************************************************************************************%*/
|
|
|
73 |
// CONSTRUCTOR
|
|
|
74 |
|
|
|
75 |
/**
|
|
|
76 |
* Constructs a new instance of the <CFCredential> class.
|
|
|
77 |
*/
|
|
|
78 |
public function __construct($value = array())
|
|
|
79 |
{
|
|
|
80 |
$this->collection = new ArrayObject($value, ArrayObject::ARRAY_AS_PROPS);
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Check whether or not a specific offset exists.
|
|
|
85 |
*
|
|
|
86 |
* @param integer $offset (Required) The location in the collection to verify the existence of.
|
|
|
87 |
* @return boolean A value of <code>true</code> indicates that the collection offset exists. A value of <code>false</code> indicates that it does not.
|
|
|
88 |
*/
|
|
|
89 |
public function offsetExists($offset)
|
|
|
90 |
{
|
|
|
91 |
return $this->collection->offsetExists($offset);
|
|
|
92 |
}
|
|
|
93 |
|
|
|
94 |
/**
|
|
|
95 |
* Get the value for a specific offset.
|
|
|
96 |
*
|
|
|
97 |
* @param integer $offset (Required) The location in the collection to retrieve the value for.
|
|
|
98 |
* @return mixed The value of the collection offset. <code>NULL</code> is returned if the offset does not exist.
|
|
|
99 |
*/
|
|
|
100 |
public function offsetGet($offset)
|
|
|
101 |
{
|
|
|
102 |
if ($this->collection->offsetExists($offset))
|
|
|
103 |
{
|
|
|
104 |
return $this->collection->offsetGet($offset);
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
return null;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
/**
|
|
|
111 |
* Set the value for a specific offset.
|
|
|
112 |
*
|
|
|
113 |
* @param integer $offset (Required) The location in the collection to set a new value for.
|
|
|
114 |
* @param mixed $value (Required) The new value for the collection location.
|
|
|
115 |
* @return CFCredential A reference to the current collection.
|
|
|
116 |
*/
|
|
|
117 |
public function offsetSet($offset, $value)
|
|
|
118 |
{
|
|
|
119 |
$this->collection->offsetSet($offset, $value);
|
|
|
120 |
return $this;
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
/**
|
|
|
124 |
* Unset the value for a specific offset.
|
|
|
125 |
*
|
|
|
126 |
* @param integer $offset (Required) The location in the collection to unset.
|
|
|
127 |
* @return CFCredential A reference to the current collection.
|
|
|
128 |
*/
|
|
|
129 |
public function offsetUnset($offset)
|
|
|
130 |
{
|
|
|
131 |
$this->collection->offsetUnset($offset);
|
|
|
132 |
return $this;
|
|
|
133 |
}
|
|
|
134 |
|
|
|
135 |
/**
|
|
|
136 |
* Merge another instance of <CFCredential> onto this one.
|
|
|
137 |
*
|
|
|
138 |
* @param CFCredential $credential (Required) Another instance of <CFCredential>.
|
|
|
139 |
* @return CFCredential A reference to the current collection.
|
|
|
140 |
*/
|
|
|
141 |
public function merge(CFCredential $credential)
|
|
|
142 |
{
|
|
|
143 |
$merged = array_merge($this->to_array(), $credential->to_array());
|
|
|
144 |
$this->collection->exchangeArray($merged);
|
|
|
145 |
return $this;
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
/**
|
|
|
149 |
* Retrieves the data as a standard array.
|
|
|
150 |
*
|
|
|
151 |
* @return array The data as an array.
|
|
|
152 |
*/
|
|
|
153 |
public function to_array()
|
|
|
154 |
{
|
|
|
155 |
return $this->collection->getArrayCopy();
|
|
|
156 |
}
|
|
|
157 |
}
|