1 |
<?php
|
2 |
/*
|
3 |
* $Id: Access.php 3189 2007-11-18 20:37:44Z meus $
|
4 |
*
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
16 |
*
|
17 |
* This software consists of voluntary contributions made by many individuals
|
18 |
* and is licensed under the LGPL. For more information, see
|
19 |
* <http://www.phpdoctrine.com>.
|
20 |
*/
|
21 |
|
22 |
/**
|
23 |
* Doctrine_Access
|
24 |
*
|
25 |
* the purpose of Doctrine_Access is to provice array access
|
26 |
* and property overload interface for subclasses
|
27 |
*
|
28 |
* @package Doctrine
|
29 |
* @subpackage Access
|
30 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
31 |
* @link www.phpdoctrine.com
|
32 |
* @since 1.0
|
33 |
* @version $Revision: 3189 $
|
34 |
* @author Konsta Vesterinen <kvesteri@cc.hut.fi>
|
35 |
*/
|
36 |
abstract class Doctrine_Access extends Doctrine_Locator_Injectable implements ArrayAccess
|
37 |
{
|
38 |
/**
|
39 |
* setArray
|
40 |
*
|
41 |
* @param array $array an array of key => value pairs
|
42 |
* @since 1.0
|
43 |
* @return Doctrine_Access
|
44 |
*/
|
45 |
public function setArray(array $array)
|
46 |
{
|
47 |
foreach ($array as $k=>$v) {
|
48 |
$this->set($k,$v);
|
49 |
}
|
50 |
|
51 |
return $this;
|
52 |
}
|
53 |
|
54 |
/**
|
55 |
* __set an alias of set()
|
56 |
*
|
57 |
* @see set, offsetSet
|
58 |
* @param $name
|
59 |
* @param $value
|
60 |
* @since 1.0
|
61 |
* @return void
|
62 |
*/
|
63 |
public function __set($name,$value)
|
64 |
{
|
65 |
$this->set($name,$value);
|
66 |
}
|
67 |
|
68 |
/**
|
69 |
* __get -- an alias of get()
|
70 |
*
|
71 |
* @see get, offsetGet
|
72 |
* @param mixed $name
|
73 |
* @since 1.0
|
74 |
* @return mixed
|
75 |
*/
|
76 |
public function __get($name)
|
77 |
{
|
78 |
return $this->get($name);
|
79 |
}
|
80 |
|
81 |
/**
|
82 |
* __isset()
|
83 |
*
|
84 |
* @param string $name
|
85 |
* @since 1.0
|
86 |
* @return boolean whether or not this object contains $name
|
87 |
*/
|
88 |
public function __isset($name)
|
89 |
{
|
90 |
return $this->contains($name);
|
91 |
}
|
92 |
|
93 |
/**
|
94 |
* __unset()
|
95 |
*
|
96 |
* @param string $name
|
97 |
* @since 1.0
|
98 |
* @return void
|
99 |
*/
|
100 |
public function __unset($name)
|
101 |
{
|
102 |
return $this->remove($name);
|
103 |
}
|
104 |
|
105 |
/**
|
106 |
* Check if an offsetExists. Alias for contains.
|
107 |
*
|
108 |
* @param mixed $offset
|
109 |
* @return boolean whether or not this object contains $offset
|
110 |
*/
|
111 |
public function offsetExists($offset)
|
112 |
{
|
113 |
return $this->contains($offset);
|
114 |
}
|
115 |
|
116 |
/**
|
117 |
* offsetGet an alias of get()
|
118 |
*
|
119 |
* @see get, __get
|
120 |
* @param mixed $offset
|
121 |
* @return mixed
|
122 |
*/
|
123 |
public function offsetGet($offset)
|
124 |
{
|
125 |
return $this->get($offset);
|
126 |
}
|
127 |
|
128 |
/**
|
129 |
* sets $offset to $value
|
130 |
* @see set, __set
|
131 |
* @param mixed $offset
|
132 |
* @param mixed $value
|
133 |
* @return void
|
134 |
*/
|
135 |
public function offsetSet($offset, $value)
|
136 |
{
|
137 |
if ( ! isset($offset)) {
|
138 |
$this->add($value);
|
139 |
} else {
|
140 |
$this->set($offset, $value);
|
141 |
}
|
142 |
}
|
143 |
|
144 |
/**
|
145 |
* unset a given offset
|
146 |
* @see set, offsetSet, __set
|
147 |
* @param mixed $offset
|
148 |
*/
|
149 |
public function offsetUnset($offset)
|
150 |
{
|
151 |
return $this->remove($offset);
|
152 |
}
|
153 |
}
|