1 |
<?php
|
2 |
/*
|
3 |
* $Id: Object.php 2702 2007-10-03 21:43:22Z Jonathan.Wage $
|
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 |
* @subpackage Schema
|
28 |
* @link www.phpdoctrine.com
|
29 |
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
|
30 |
* @since 1.0
|
31 |
* @version $Revision: 2702 $
|
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 |
{
|
37 |
|
38 |
protected $children = array();
|
39 |
|
40 |
protected $definition = array('name' => '');
|
41 |
|
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 |
}
|
49 |
|
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];
|
56 |
|
57 |
}
|
58 |
|
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 |
}
|
66 |
|
67 |
public function contains($name)
|
68 |
{
|
69 |
return array_key_exists($name, $this->definition);
|
70 |
}
|
71 |
|
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 |
}
|
88 |
|
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 |
}
|