<?php
/*
* ClientStartup.php is copyright � 2010. EarthWalk Software.
* Licensed under the Academic Free License version 3.0.
* Refer to the file named License provided with the source.
*/
/**
* IGSConfig
*
* php5 / ZendFramework-1.7.2 implementation of a Zend_Config_XML configuration file loader.
* @author Jay Wheeler
* @version 1.0
* @copyright � 2010. EarthWalk Software.
* @license refer to License file provided with the source.
* @package IGSGateway
* @subpackage IGSConfig
*/
class IGSConfig
{
/**
* xml.
*
* A pointer to the Zend_Config_Xml object.
* @var Zend_Config_Xml
*/
private static $xml = null;
/**
* valid.
*
* true = valid, false = not.
* @var boolean
*/
private static $valid = false;
/**
* config.
*
* xml configuration file name
* @var string
*/
private static $config = null;
/**
* section.
*
* xml configuration section.
* @var string
*/
private static $section = null;
/**
* exception.
*
* true = exception occurred, else none
* @var boolean
*/
private static $exception = false;
/**
* error.
*
* Exception error message.
* @var string
*/
private static $error = '';
/*
* load
*
* Static function to load the configuration file
* @param string $config = (optional) xml configuration file name
* @param string $section = (optional) section to load (production or development)
* @return boolean true = successful, false = unsuccessful
*/
public static function load($config=null, $section=null)
{
if (($config == self::$config) &&
($section == self::$section) &&
self::$valid)
{
return true;
}
if ($config)
{
self::$config = $config;
}
else
{
$config = self::$config;
}
if (! $config)
{
self::$exception = true;
self::$error = 'Missing XML configuration file name';
return false;
}
//
// Check for configuration section requested
//
if ($section)
{
self::$section = $section;
}
else
{
$section = self::$section;
}
try
{
if ($section)
{
self::$xml = new Zend_Config_Xml($config, $section);
}
else
{
self::$xml = new Zend_Config_Xml($config);
}
}
catch(Zend_Exception $exception)
{
self::$exception = true;
self::$error = $exception->getMessage();
return false;
}
self::$valid = true;
return true;
}
// ******************************************************************************
/*
* valid
*
* Return the current valid flag
* @return boolean true = valid, false = invalid
*/
public static function valid()
{
return self::$valid;
}
// ******************************************************************************
/*
* xml
*
* Return the reference to the Zend_Config_XML object
* @return Zend_Config_XML reference
*/
public static function xml()
{
if (! self::$valid)
{
return false;
}
return self::$xml;
}
// ******************************************************************************
/*
* exception
*
* Return the current exception value
* @return integer = current exeption value
*/
public static function exception()
{
return self::$exception;
}
// ******************************************************************************
/*
* error
*
* Return the current error value
* @return integer = current error value
*/
public static function error()
{
return self::$error;
}
// ******************************************************************************
/*
* config
*
* Set/get current configuration name
* @param string $config = (optional) configuration name to set
* @return string = current configuration name
*/
public static function config($config=null)
{
if ($config)
{
self::$config = $config;
}
return self::$config;
}
// ******************************************************************************
/*
* section
*
* Set/get current section
* @param string $section = (optional) configuration section name to set
* @return string = current configuration section name
*/
public static function section($section=null)
{
if ($section)
{
self::$section = $section;
}
return self::$section;
}
}