# Source for file Access.php

Documentation is available at Access.php

1. <?php
2. /*
3. * $Id: Access.php 1604 2007-06-08 19:07:32Z zYne $
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. * Doctrine_Access
23. *
24. * the purpose of Doctrine_Access is to provice array access
25. * and property overload interface for subclasses
26. *
27. * @package Doctrine
28. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
29. * @category Object Relational Mapping
30. * @link www.phpdoctrine.com
31. * @since 1.0
32. * @version $Revision: 1604 $
33. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
34. */
35. abstract class Doctrine_Access extends Doctrine_Object implements ArrayAccess
36. {
37. /**
38. * setArray
39. *
40. * @param array $array an array of key => value pairs
41. * @since 1.0
42. * @return Doctrine_Access
43. */
44. public function setArray(array $array)
45. {
46. foreach ($array as $k=>$v) {
47. $this->set($k,$v);
48. }
50. return $this;
51. }
52. /**
53. * __set an alias of set()
54. *
55. * @see set, offsetSet
56. * @param $name
57. * @param $value
58. * @since 1.0
59. * @return void
60. */
61. public function __set($name,$value)
62. {
63. $this->set($name,$value);
64. }
65. /**
66. * __get -- an alias of get()
67. *
68. * @see get, offsetGet
69. * @param mixed $name
70. * @since 1.0
71. * @return mixed
72. */
73. public function __get($name)
74. {
75. return $this->get($name);
76. }
77. /**
78. * __isset()
79. *
80. * @param string $name
81. * @since 1.0
82. * @return boolean whether or not this object contains $name
83. */
84. public function __isset($name)
85. {
86. return $this->contains($name);
87. }
88. /**
89. * __unset()
90. *
91. * @param string $name
92. * @since 1.0
93. * @return void
94. */
95. public function __unset($name)
96. {
97. return $this->remove($name);
98. }
99. /**
100. * @param mixed $offset
101. * @return boolean whether or not this object contains $offset
102. */
103. public function offsetExists($offset)
104. {
105. return $this->contains($offset);
106. }
107. /**
108. * offsetGet an alias of get()
109. * @see get, __get
110. * @param mixed $offset
111. * @return mixed
112. */
113. public function offsetGet($offset)
114. {
115. return $this->get($offset);
116. }
117. /**
118. * sets $offset to $value
119. * @see set, __set
120. * @param mixed $offset
121. * @param mixed $value
122. * @return void
123. */
124. public function offsetSet($offset, $value)
125. {
126. if ( ! isset($offset)) {
127. $this->add($value);
128. } else {
129. $this->set($offset, $value);
130. }
131. }
132. /**
133. * unset a given offset
134. * @see set, offsetSet, __set
135. * @param mixed $offset
136. */
137. public function offsetUnset($offset)
138. {
139. return $this->remove($offset);
140. }
141. }