# Source for file Column.php

Documentation is available at Column.php

1. <?php
2. /*
3. * $Id: Column.php 1392 2007-05-19 17:29:43Z 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_Column
23. * This class represents a database column
24. *
25. * @author Konsta Vesterinen <kvesteri@cc.hut.fi>
26. * @package Doctrine
27. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
28. * @version $Revision: 1392 $
29. * @category Object Relational Mapping
30. * @link www.phpdoctrine.com
31. * @since 1.0
32. */
33. class Doctrine_Column extends Doctrine_Access implements IteratorAggregate, Countable
34. {
35. /**
36. * @var array $definition
37. */
38. protected $_definition = array(
39. 'type' => null,
40. 'length' => 0,
41. );
42. /**
43. * @var array $definition
44. */
45. public function __construct(array $definition = array())
46. {
47. $this->_definition = $definition;
48. }
49. /**
50. * @return array
51. */
52. public function getDefinition()
53. {
54. return $this->_definition;
55. }
56. /**
57. * contains
58. *
59. * @return boolean
60. */
61. public function contains($name)
62. {
63. return isset($this->_definition[$name]);
64. }
65. /**
66. * get
67. *
68. * @param string $name
69. * @return mixed
70. */
71. public function get($name)
72. {
73. if ( ! isset($this->_definition[$name])) {
74. return null;
75. }
77. return $this->_definition[$name];
78. }
79. /**
80. * set
81. *
82. * @param string $name
83. * @return mixed
84. */
85. public function set($name, $value)
86. {
87. $this->_definition[$name] = $value;
88. }
89. /**
90. * @param string $field
91. * @return array
92. */
93. public function getEnumValues()
94. {
95. if (isset($this->_definition['values'])) {
96. return $this->_definition['values'];
97. } else {
98. return array();
99. }
100. }
101. /**
102. * enumValue
103. *
104. * @param string $field
105. * @param integer $index
106. * @return mixed
107. */
108. public function enumValue($index)
109. {
110. if ($index instanceof Doctrine_Null) {
111. return $index;
112. }
114. return isset($this->_definition['values'][$index]) ? $this->_definition['values'][$index] : $index;
115. }
116. /**
117. * enumIndex
118. *
119. * @param string $field
120. * @param mixed $value
121. * @return mixed
122. */
123. public function enumIndex($field, $value)
124. {
125. $values = $this->getEnumValues($field);
127. return array_search($value, $values);
128. }
129. /**
130. * count
131. *
132. * @return integer
133. */
134. public function count()
135. {
136. return count($this->_definition);
137. }
138. /**
139. * getIterator
140. *
141. * @return ArrayIterator
142. */
143. public function getIterator()
144. {
145. return new ArrayIterator($this->_definition);
146. }
148. }