~cdparra/gelee/trunk

« back to all changes in this revision

Viewing changes to webui/ecosystem/workspace/ecosystem/uwa-server-original/server/lib/Zend/Config.php

  • Committer: parra
  • Date: 2010-03-15 02:39:02 UTC
  • Revision ID: svn-v4:ac5bba68-f036-4e09-846e-8f32731cc928:trunk/gelee:1433
merged gelee at svn

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Zend Framework
 
5
 *
 
6
 * LICENSE
 
7
 *
 
8
 * This source file is subject to the new BSD license that is bundled
 
9
 * with this package in the file LICENSE.txt.
 
10
 * It is also available through the world-wide-web at this URL:
 
11
 * http://framework.zend.com/license/new-bsd
 
12
 * If you did not receive a copy of the license and are unable to
 
13
 * obtain it through the world-wide-web, please send an email
 
14
 * to license@zend.com so we can send you a copy immediately.
 
15
 *
 
16
 * @category   Zend
 
17
 * @package    Zend_Config
 
18
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
19
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
20
 * @version    $Id: Config.php 8064 2008-02-16 10:58:39Z thomas $
 
21
 */
 
22
 
 
23
 
 
24
/**
 
25
 * @category   Zend
 
26
 * @package    Zend_Config
 
27
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 
28
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 
29
 */
 
30
class Zend_Config implements Countable, Iterator
 
31
{
 
32
    /**
 
33
     * Whether in-memory modifications to configuration data are allowed
 
34
     *
 
35
     * @var boolean
 
36
     */
 
37
    protected $_allowModifications;
 
38
 
 
39
    /**
 
40
     * Iteration index
 
41
     *
 
42
     * @var integer
 
43
     */
 
44
    protected $_index;
 
45
 
 
46
    /**
 
47
     * Number of elements in configuration data
 
48
     *
 
49
     * @var integer
 
50
     */
 
51
    protected $_count;
 
52
 
 
53
    /**
 
54
     * Contains array of configuration data
 
55
     *
 
56
     * @var array
 
57
     */
 
58
    protected $_data;
 
59
 
 
60
 
 
61
    /**
 
62
     * Contains which config file sections were loaded. This is null
 
63
     * if all sections were loaded, a string name if one section is loaded
 
64
     * and an array of string names if multiple sections were loaded.
 
65
     *
 
66
     * @var mixed
 
67
     */
 
68
    protected $_loadedSection;
 
69
 
 
70
    /**
 
71
     * This is used to track section inheritance. The keys are names of sections that
 
72
     * extend other sections, and the values are the extended sections.
 
73
     *
 
74
     * @var array
 
75
     */
 
76
    protected $_extends = array();
 
77
 
 
78
    /**
 
79
     * Zend_Config provides a property based interface to
 
80
     * an array. The data are read-only unless $allowModifications
 
81
     * is set to true on construction.
 
82
     *
 
83
     * Zend_Config also implements Countable and Iterator to
 
84
     * facilitate easy access to the data.
 
85
     *
 
86
     * @param  array   $array
 
87
     * @param  boolean $allowModifications
 
88
     * @return void
 
89
     */
 
90
    public function __construct($array, $allowModifications = false)
 
91
    {
 
92
        $this->_allowModifications = (boolean) $allowModifications;
 
93
        $this->_loadedSection = null;
 
94
        $this->_index = 0;
 
95
        $this->_data = array();
 
96
        foreach ($array as $key => $value) {
 
97
            if (is_array($value)) {
 
98
                $this->_data[$key] = new self($value, $this->_allowModifications);
 
99
            } else {
 
100
                $this->_data[$key] = $value;
 
101
            }
 
102
        }
 
103
        $this->_count = count($this->_data);
 
104
    }
 
105
 
 
106
    /**
 
107
     * Retrieve a value and return $default if there is no element set.
 
108
     *
 
109
     * @param string $name
 
110
     * @param mixed $default
 
111
     * @return mixed
 
112
     */
 
113
    public function get($name, $default = null)
 
114
    {
 
115
        $result = $default;
 
116
        if (array_key_exists($name, $this->_data)) {
 
117
            $result = $this->_data[$name];
 
118
        }
 
119
        return $result;
 
120
    }
 
121
 
 
122
    /**
 
123
     * Magic function so that $obj->value will work.
 
124
     *
 
125
     * @param string $name
 
126
     * @return mixed
 
127
     */
 
128
    public function __get($name)
 
129
    {
 
130
        return $this->get($name);
 
131
    }
 
132
 
 
133
    /**
 
134
     * Only allow setting of a property if $allowModifications
 
135
     * was set to true on construction. Otherwise, throw an exception.
 
136
     *
 
137
     * @param  string $name
 
138
     * @param  mixed  $value
 
139
     * @throws Zend_Config_Exception
 
140
     * @return void
 
141
     */
 
142
    public function __set($name, $value)
 
143
    {
 
144
        if ($this->_allowModifications) {
 
145
            if (is_array($value)) {
 
146
                $this->_data[$name] = new self($value, true);
 
147
            } else {
 
148
                $this->_data[$name] = $value;
 
149
            }
 
150
            $this->_count = count($this->_data);
 
151
        } else {
 
152
            /** @see Zend_Config_Exception */
 
153
            require_once 'Zend/Config/Exception.php';
 
154
            throw new Zend_Config_Exception('Zend_Config is read only');
 
155
        }
 
156
    }
 
157
 
 
158
    /**
 
159
     * Return an associative array of the stored data.
 
160
     *
 
161
     * @return array
 
162
     */
 
163
    public function toArray()
 
164
    {
 
165
        $array = array();
 
166
        foreach ($this->_data as $key => $value) {
 
167
            if ($value instanceof Zend_Config) {
 
168
                $array[$key] = $value->toArray();
 
169
            } else {
 
170
                $array[$key] = $value;
 
171
            }
 
172
        }
 
173
        return $array;
 
174
    }
 
175
 
 
176
    /**
 
177
     * Support isset() overloading on PHP 5.1
 
178
     *
 
179
     * @param string $name
 
180
     * @return boolean
 
181
     */
 
182
    protected function __isset($name)
 
183
    {
 
184
        return isset($this->_data[$name]);
 
185
    }
 
186
 
 
187
    /**
 
188
     * Support unset() overloading on PHP 5.1
 
189
     *
 
190
     * @param  string $name
 
191
     * @throws Zend_Config_Exception
 
192
     * @return void
 
193
     */
 
194
    protected function __unset($name)
 
195
    {
 
196
        if ($this->_allowModifications) {
 
197
            unset($this->_data[$name]);
 
198
        } else {
 
199
            /** @see Zend_Config_Exception */
 
200
            require_once 'Zend/Config/Exception.php';
 
201
            throw new Zend_Config_Exception('Zend_Config is read only');
 
202
        }
 
203
 
 
204
    }
 
205
 
 
206
    /**
 
207
     * Defined by Countable interface
 
208
     *
 
209
     * @return int
 
210
     */
 
211
    public function count()
 
212
    {
 
213
        return $this->_count;
 
214
    }
 
215
 
 
216
    /**
 
217
     * Defined by Iterator interface
 
218
     *
 
219
     * @return mixed
 
220
     */
 
221
    public function current()
 
222
    {
 
223
        return current($this->_data);
 
224
    }
 
225
 
 
226
    /**
 
227
     * Defined by Iterator interface
 
228
     *
 
229
     * @return mixed
 
230
     */
 
231
    public function key()
 
232
    {
 
233
        return key($this->_data);
 
234
    }
 
235
 
 
236
    /**
 
237
     * Defined by Iterator interface
 
238
     *
 
239
     */
 
240
    public function next()
 
241
    {
 
242
        next($this->_data);
 
243
        $this->_index++;
 
244
    }
 
245
 
 
246
    /**
 
247
     * Defined by Iterator interface
 
248
     *
 
249
     */
 
250
    public function rewind()
 
251
    {
 
252
        reset($this->_data);
 
253
        $this->_index = 0;
 
254
    }
 
255
 
 
256
    /**
 
257
     * Defined by Iterator interface
 
258
     *
 
259
     * @return boolean
 
260
     */
 
261
    public function valid()
 
262
    {
 
263
        return $this->_index < $this->_count;
 
264
    }
 
265
 
 
266
    /**
 
267
     * Returns the section name(s) loaded.
 
268
     *
 
269
     * @return mixed
 
270
     */
 
271
    public function getSectionName()
 
272
    {
 
273
        return $this->_loadedSection;
 
274
    }
 
275
 
 
276
    /**
 
277
     * Returns true if all sections were loaded
 
278
     *
 
279
     * @return boolean
 
280
     */
 
281
    public function areAllSectionsLoaded()
 
282
    {
 
283
        return $this->_loadedSection === null;
 
284
    }
 
285
 
 
286
 
 
287
    /**
 
288
     * Merge another Zend_Config with this one. The items
 
289
     * in $merge will override the same named items in
 
290
     * the current config.
 
291
     *
 
292
     * @param Zend_Config $merge
 
293
     * @return Zend_Config
 
294
     */
 
295
    public function merge(Zend_Config $merge)
 
296
    {
 
297
        foreach($merge as $key => $item) {
 
298
            if(array_key_exists($key, $this->_data)) {
 
299
                if($item instanceof Zend_Config && $this->$key instanceof Zend_Config) {
 
300
                    $this->$key = $this->$key->merge($item);
 
301
                } else {
 
302
                    $this->$key = $item;
 
303
                }
 
304
            } else {
 
305
                $this->$key = $item;
 
306
            }
 
307
        }
 
308
 
 
309
        return $this;
 
310
    }
 
311
 
 
312
    /**
 
313
     * Prevent any more modifications being made to this instance. Useful
 
314
     * after merge() has been used to merge multiple Zend_Config objects
 
315
     * into one object which should then not be modified again.
 
316
     *
 
317
     */
 
318
    public function setReadOnly()
 
319
    {
 
320
        $this->_allowModifications = false;
 
321
    }
 
322
 
 
323
    /**
 
324
     * Throws an exception if $extendingSection may not extend $extendedSection,
 
325
     * and tracks the section extension if it is valid.
 
326
     *
 
327
     * @param  string $extendingSection
 
328
     * @param  string $extendedSection
 
329
     * @throws Zend_Config_Exception
 
330
     * @return void
 
331
     */
 
332
    protected function _assertValidExtend($extendingSection, $extendedSection)
 
333
    {
 
334
        // detect circular section inheritance
 
335
        $extendedSectionCurrent = $extendedSection;
 
336
        while (array_key_exists($extendedSectionCurrent, $this->_extends)) {
 
337
            if ($this->_extends[$extendedSectionCurrent] == $extendingSection) {
 
338
                /** @see Zend_Config_Exception */
 
339
                require_once 'Zend/Config/Exception.php';
 
340
                throw new Zend_Config_Exception('Illegal circular inheritance detected');
 
341
            }
 
342
            $extendedSectionCurrent = $this->_extends[$extendedSectionCurrent];
 
343
        }
 
344
        // remember that this section extends another section
 
345
        $this->_extends[$extendingSection] = $extendedSection;
 
346
    }
 
347
 
 
348
}