| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: PropelConfigurationIterator.php 1262 2009-10-26 20:54:39Z francois $
|
|
|
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 please see
|
|
|
19 |
* <http://propel.phpdb.org>.
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
/**
|
|
|
23 |
* PropelConfigurationIterator is used internally by PropelConfiguration to
|
|
|
24 |
* build a flat array from nesting configuration arrays.
|
|
|
25 |
*
|
|
|
26 |
* @author Veikko Mäkinen <veikko@veikko.fi>
|
|
|
27 |
* @version $Revision: 1262 $
|
|
|
28 |
* @package propel
|
|
|
29 |
*/
|
|
|
30 |
class PropelConfigurationIterator extends RecursiveIteratorIterator
|
|
|
31 |
{
|
|
|
32 |
/**
|
|
|
33 |
* Node is a parent node
|
|
|
34 |
*/
|
|
|
35 |
const NODE_PARENT = 0;
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Node is an actual configuration item
|
|
|
39 |
*/
|
|
|
40 |
const NODE_ITEM = 1;
|
|
|
41 |
|
|
|
42 |
/**
|
|
|
43 |
* Namespace stack when recursively iterating the configuration tree
|
|
|
44 |
*
|
|
|
45 |
* @var array
|
|
|
46 |
*/
|
|
|
47 |
protected $namespaceStack = array();
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Current node type. Possible values: null (undefined), self::NODE_PARENT or self::NODE_ITEM
|
|
|
51 |
*
|
|
|
52 |
* @var int
|
|
|
53 |
*/
|
|
|
54 |
protected $nodeType = null;
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* Get current namespace
|
|
|
58 |
*
|
|
|
59 |
* @return string
|
|
|
60 |
*/
|
|
|
61 |
public function getNamespace()
|
|
|
62 |
{
|
|
|
63 |
return implode('.', $this->namespaceStack);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
/**
|
|
|
67 |
* Get current node type.
|
|
|
68 |
*
|
|
|
69 |
* @see http://www.php.net/RecursiveIteratorIterator
|
|
|
70 |
* @return int
|
|
|
71 |
* - null (undefined)
|
|
|
72 |
* - self::NODE_PARENT
|
|
|
73 |
* - self::NODE_ITEM
|
|
|
74 |
*/
|
|
|
75 |
public function getNodeType()
|
|
|
76 |
{
|
|
|
77 |
return $this->nodeType;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
/**
|
|
|
81 |
* Get the current element
|
|
|
82 |
*
|
|
|
83 |
* @see http://www.php.net/RecursiveIteratorIterator
|
|
|
84 |
* @return mixed
|
|
|
85 |
*/
|
|
|
86 |
public function current()
|
|
|
87 |
{
|
|
|
88 |
$current = parent::current();
|
|
|
89 |
if (is_array($current)) {
|
|
|
90 |
$this->namespaceStack[] = $this->key();
|
|
|
91 |
$this->nodeType = self::NODE_PARENT;
|
|
|
92 |
}
|
|
|
93 |
else {
|
|
|
94 |
$this->nodeType = self::NODE_ITEM;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
return $current;
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
/**
|
|
|
101 |
* Called after current child iterator is invalid and right before it gets destructed.
|
|
|
102 |
*
|
|
|
103 |
* @see http://www.php.net/RecursiveIteratorIterator
|
|
|
104 |
*/
|
|
|
105 |
public function endChildren()
|
|
|
106 |
{
|
|
|
107 |
if ($this->namespaceStack) {
|
|
|
108 |
array_pop($this->namespaceStack);
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
?>
|