# Source for file Object.php

Documentation is available at Object.php

1. <?php
2. /*
3. * $Id: Object.php 1080 2007-02-10 18:17:08Z romanb $
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. Doctrine::autoload('Doctrine_Access');
22. /**
23. * class Doctrine_Schema_Object
24. * Catches any non-property call from child classes and throws an exception.
25. *
26. * @package Doctrine
27. * @category Object Relational Mapping
28. * @link www.phpdoctrine.com
29. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
30. * @since 1.0
31. * @version $Revision: 1080 $
32. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
33. * @author Jukka Hassinen <Jukka.Hassinen@BrainAlliance.com>
34. */
35. abstract class Doctrine_Schema_Object extends Doctrine_Access implements IteratorAggregate, Countable
36. {
38. protected $children = array();
40. protected $definition = array('name' => '');
42. public function __construct(array $definition = array()) {
43. foreach ($this->definition as $key => $val) {
44. if (isset($definition[$key])) {
45. $this->definition[$key] = $definition[$key];
46. }
47. }
48. }
50. public function get($name)
51. {
52. if ( ! array_key_exists($name, $this->definition)) {
53. throw new Doctrine_Schema_Exception('Unknown definition '. $name);
54. }
55. return $this->definition[$name];
57. }
59. public function set($name, $value)
60. {
61. if ( ! array_key_exists($name, $this->definition)) {
62. throw new Doctrine_Schema_Exception('Unknown definition '. $name);
63. }
64. $this->definition[$name] = $value;
65. }
67. public function contains($name)
68. {
69. return array_key_exists($name, $this->definition);
70. }
72. public function toArray()
73. {
74. return $this->definition;
75. }
76. /**
77. *
78. * @return int
79. * @access public
80. */
81. public function count()
82. {
83. if ( ! empty($this->children)) {
84. return count($this->children);
85. }
86. return count($this->definition);
87. }
89. /**
90. * getIterator
91. *
92. * @return ArrayIterator
93. * @access public
94. */
95. public function getIterator()
96. {
97. if ( ! empty($this->children)) {
98. return new ArrayIterator($this->children);
99. }
100. return new ArrayIterator($this->definition);
101. }
102. }