Location: PHPKode > projects > RSS Framework for PHP > src/classes/xmlbaseclass.php
<?php error_reporting(E_ALL);
/**
 * This file is part of the Dynamic Networks RSS Framework for PHP
 * 
 * @author Gordon Oheim (hide@address.com)
 * @copyright Copyright 2005, Dynamic Networks
 * @link http://www.dynamicnetworks.de
 * @license http://creativecommons.org/licenses/GPL/2.0/ GNU General Public License
 * @filesource
 * @version 1.0.0
 */

/**
 * XMLBaseClass is the base class for XML objects
 * 
 * XMLBaseClass is the base class for alle XML objects within the framework. It
 * supports each class with a number of methods and attributes that are shared
 * alike by all or most classes.
 *
 * @package rssFramework/mediaRSS
 * @author Gordon Oheim (hide@address.com)
 */ 
class xmlbaseclass {
	
	/**
	 * Specifies the namespace URI
	 * 
	 * @var string
	 */
	var $namespace;
	
	/**
	 * specifies the prefix for this module
	 * 
	 * @var string
	 */
	var $prefix;

	/**
	 * holds modules that use a different namespace than the default one.
	 * 
	 * @var object
	 */
	var $module;


	/**
	 * Sets the namespace to be used in the RSS feed.
	 * 
	 * This function sets the namespace that will be used for the module
	 * throughout the RSS feed. This must be a unique identifier, usually in the
	 * form of a uri, but not necessarily pointing to a real resource. This is a
	 * required attribute.
	 * 
	 * @param string $namespace
	 * @access public
	 * @see get_namespace()
	 */
	function set_namespace($namespace) {
		if (is_string($namespace)) {
			$this->namespace = $namespace;
		} else {
			die("FATAL ERROR: added param is not a string");
		}	
	}

	/**
	 * Sets the prefix to be used in the RSS feed.
	 * 
	 * This function sets the prefix that will be used for the module throughout
	 * the RSS feed. This is a required attribute. Please note, that the
	 * framework will not perform any checking if there is already another
	 * module with the same prefix defined.
	 * 
	 * @param string $prefix
	 * @access public
	 * @see get_prefix()
	 */
	function set_prefix($prefix) {
		if (is_string($prefix)) {
			$this->prefix = $prefix;
		} else {
			die("FATAL ERROR: added param is not a string");
		}
	}
	
	/**
  	 * Adds a module object to the object instance
  	 * 
  	 * This function adds a new module object to the modules attribute. Module
  	 * objects hold object that represent XML modules that differ from the
  	 * default namespace.
  	 * 
  	 * @param module $module
  	 * @see get_module()
  	 * @see remove_module()
  	 * @access public
  	 */
	function set_module($module) {
		if (is_array($module)) {
			foreach($module as $object) {
				$this->set_module($object);
			}
		}
		else {
			$this->module[] = $module;
		}
	}
	
	/**
	 * Returns the namespace attribute
	 * 
	 * @return string
	 * @access public
	 * @see set_namespace
	 */
	function get_namespace() {
		return $this->namespace;	
	}

	/**
	 * Returns the prefix attribute
	 * 
	 * @return string
	 * @access public
	 * @see set_prefix
	 */	function get_prefix() {
		return $this->prefix;
	}
	
	/**
	 * Returns the value of the attribute module
	 * 
	 * @return module[]
	 * @access public
	 * @see set_module()
	 * @see remove_module()
	 */
	function get_module() {
		return $this->module;
	}
	
	/**
	 * Removes objects from the module array.
	 * 
	 * This function removes the module object located at the specified index by
	 * the param and reindexes the array. The function will return true on
	 * success. This class is a wrapper for the function remove_from_array().
	 * Note: As of this writing there are no shorts in PHP. Use integer instead.
	 * 
	 * @access public
	 * @param short $index
	 * @return bool
	 * @see get_module()
	 * @see set_module()
	 * @see remove_from_array();
	 */	
	function remove_module($index) {
		return $this->remove_from_array($this->module, $index);	
	}	
	
	/**
	 * Unsets an array element.
	 * 
	 * This function removes the element located at the $index of the specified
	 * array and returns true on success. This method is private and should not
	 * be called by your program. Use the appropriate methods for the elements
	 * you want to remove instead.
	 * 
	 * @access private
	 * @param array $array
	 * @param short $index
	 * @return bool
	 */
	function remove_from_array(&$array, $index) {
		if (is_integer($index)) {
			if (isset($array[$index])) {
				unset($array[$index]);
				$array = array_values($array);
				return true;
			} else {
				return false;
			}
		} else {
			return false;
		}
	}  	
	
}
Return current item: RSS Framework for PHP