Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
/*
3
 *  $Id: Column.php 7663 2010-06-08 19:00:08Z jwage $
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.doctrine-project.org>.
20
 */
21
 
22
/**
23
 * Doctrine_Column
24
 * This class represents a database column
25
 *
26
 * @author      Konsta Vesterinen <kvesteri@cc.hut.fi>
27
 * @package     Doctrine
28
 * @subpackage  Column
29
 * @license     http://www.opensource.org/licenses/lgpl-license.php LGPL
30
 * @version     $Revision: 7663 $
31
 * @link        www.doctrine-project.org
32
 * @since       1.0
33
 */
34
class Doctrine_Column extends Doctrine_Access implements IteratorAggregate, Countable
35
{
36
    /**
37
     * @var array $_definition  @see getDefinition()
38
     */
39
    protected $_definition = array(
40
                                'type'    => null,
41
                                'length'  => 0,
42
                                );
43
 
44
    /**
45
     * @var array $definition  @see getDefinition()
46
     */
47
    public function __construct(array $definition = array())
48
    {
49
        $this->_definition = $definition;
50
    }
51
 
52
    /**
53
     * Returns the definition of the column.
54
     *
55
     * Keys can be:
56
     *     string type,
57
     *     integer length,
58
     *     array values (only for enum fields, maps integer indexes to mixed values),
59
     * @return array
60
     */
61
    public function getDefinition()
62
    {
63
        return $this->_definition;
64
    }
65
 
66
    /**
67
     * contains
68
     *
69
     * @return boolean
70
     */
71
    public function contains($name)
72
    {
73
        return isset($this->_definition[$name]);
74
    }
75
 
76
    /**
77
     * get
78
     *
79
     * @param string $name
80
     * @return mixed
81
     */
82
    public function get($name)
83
    {
84
        if ( ! isset($this->_definition[$name])) {
85
            return null;
86
        }
87
 
88
        return $this->_definition[$name];
89
    }
90
 
91
    /**
92
     * set
93
     *
94
     * @param string $name
95
     * @return void
96
     */
97
    public function set($name, $value)
98
    {
99
        $this->_definition[$name] = $value;
100
    }
101
 
102
    /**
103
     * @param string $field
104
     * @return array
105
     */
106
    public function getEnumValues()
107
    {
108
        if (isset($this->_definition['values'])) {
109
            return $this->_definition['values'];
110
        } else {
111
            return array();
112
        }
113
    }
114
 
115
    /**
116
     * Retrieves an enum value.
117
     *
118
     * @param integer $index
119
     * @return string       integer ($index) if not present
120
     */
121
    public function enumValue($index)
122
    {
123
        if ($index instanceof Doctrine_Null) {
124
            return false;
125
        }
126
 
127
        return isset($this->_definition['values'][$index]) ? $this->_definition['values'][$index] : false;
128
    }
129
 
130
    /**
131
     * enumIndex
132
     *
133
     * @param string $field
134
     * @param mixed $value
135
     * @return mixed
136
     */
137
    public function enumIndex($field, $value)
138
    {
139
        $values = $this->getEnumValues($field);
140
 
141
        return array_search($value, $values);
142
    }
143
 
144
    /**
145
     * count
146
     *
147
     * @return integer
148
     */
149
    public function count()
150
    {
151
        return count($this->_definition);
152
    }
153
 
154
    /**
155
     * getIterator
156
     *
157
     * @return ArrayIterator
158
     */
159
    public function getIterator()
160
    {
161
        return new ArrayIterator($this->_definition);
162
    }
163
}