Documentation is available at Crafty_Config.class.php
- <?php
- /**
- * Implementation file of the Crafty_Config class.
- *
- * <pre>
- * PROJECT : Crafty
- * Template Engine.
- * AUTHOR : Crafty Team <crafty@zulan.net>
- * COPYRIGHT : (c) Thomas Ilsche, 2004
- *
- * FILE : [ROOT]\core\Crafty_Config.class.php
- * DESCRIPTION: Implementation file of the Crafty_Config class.
- * </pre>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * @package Crafty_Compiler
- * @author Crafty Team <crafty@zulan.net>
- * @copyright Copyright (c) Thomas Ilsche 2004
- * @version 1.0.0.2004.09.15
- * @link http://crafty.zulan.net
- * @license http://www.gnu.org/licenses/lgpl.html
- * GNU Lesser General Public License Version 2.1
- ***/
- /**
- * Crafty_Config class
- *
- * This class uses simplexml to parse the config xml file and features a
- * structured object tree similar to the xml structure.<br/>
- * Aswell it allows navigation in this tree by {@link $parent} and
- * {@link $top}
- *
- * @package Crafty_Compiler
- * @author Crafty Team <crafty@zulan.net>
- * @copyright Copyright (c) Thomas Ilsche
- * @version 1.0.0.2004.09.15
- * @link http://crafty.zulan.net
- * @license http://www.gnu.org/licenses/lgpl.html
- * GNU Lesser General Public License Version 2.1
- ***/
- class Crafty_Config
- {
- /**
- * Parent node object handle in the xml tree
- *
- * @var Crafty_Config
- ***/
- public $parent;
- /**
- * Top node object handle in the xml tree
- *
- * @var Crafty_Config
- ***/
- public $top;
- /**
- * Object handle of the compiler object
- *
- * @var Crafty_Compiler
- ***/
- private $_compiler;
- /**
- * Initiates a Crafty_Config object and the corresponding object/XML tree
- *
- * When called for the first time this only needs the first parameter,
- * then it will recursively parse the XML tree and create a new Crafty_Config
- * objects for every XML tag.
- *
- * @param string $xml
- * @param Crafty_Compiler $compiler [optional,default=NULL]
- * @param Crafty_Config $parent [optional,default=NULL]
- * @param Crafty_Config $top [optional,default=NULL]
- ***/
- public function __construct($xml, $compiler = NULL, $parent = NULL, $top = NULL)
- {
- if (empty($xml)) {
- $xml = array();
- } elseif (is_string($xml)) {
- $xml = simplexml_load_file($xml);
- } elseif (!is_object($xml)) {
- throw new Crafty_Exception('Unknown error when reading the config.');
- }
- if ($parent == NULL) {
- $this->parent = NULL;
- $this->top = $this;
- if (!($compiler instanceof crafty_compiler)) {
- throw new Crafty_Exception('No crafty compiler handed over to top
- config.');
- }
- } elseif ($top == NULL) {
- $this->parent = $parent;
- $this->top = $parent;
- } else {
- $this->parent = $parent;
- $this->top = $top;
- }
- $this->_compiler = $compiler;
- foreach ($xml as $key => $value) {
- $value_str = (string)$value;
- /* We do not want the whitespace only non leaf tags in the object... */
- $value_str = preg_replace('/^\s+$/', '', $value_str);
- if (empty($value_str)) {
- $value = new Crafty_Config( $value, NULL , $this, $this->top);
- } else {
- $value = $value_str;
- $value = $this->top->_compiler->booleanize($value);
- }
- if (isset($this->$key)) {
- if (is_array($this->$key)) {
- array_push($this->$key, $value);
- } else {
- $this->$key = array($this->$key, $value);
- }
- }
- else {
- $this->$key = $value;
- }
- }
- }
- }
- ?>
Documentation generated on Sat, 19 Feb 2005 01:43:41 +0100 by phpDocumentor 1.3.0RC3