summaryrefslogtreecommitdiff
path: root/framework/Util/TParameterModule.php
diff options
context:
space:
mode:
Diffstat (limited to 'framework/Util/TParameterModule.php')
-rw-r--r--framework/Util/TParameterModule.php76
1 files changed, 54 insertions, 22 deletions
diff --git a/framework/Util/TParameterModule.php b/framework/Util/TParameterModule.php
index 529f20ca..7bc03e3b 100644
--- a/framework/Util/TParameterModule.php
+++ b/framework/Util/TParameterModule.php
@@ -4,7 +4,7 @@
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.pradosoft.com/
- * @copyright Copyright &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Util
@@ -46,63 +46,95 @@
*/
class TParameterModule extends TModule
{
+ /**
+ * @deprecated since 3.2
+ */
const PARAM_FILE_EXT='.xml';
private $_initialized=false;
private $_paramFile=null;
/**
* Initializes the module by loading parameters.
- * @param TXmlElement content enclosed within the module tag
+ * @param mixed content enclosed within the module tag
*/
public function init($config)
{
$this->loadParameters($config);
if($this->_paramFile!==null)
{
+ $configFile = null;
if(($cache=$this->getApplication()->getCache())!==null)
{
$cacheKey='TParameterModule:'.$this->_paramFile;
if(($dom=$cache->get($cacheKey))===false)
{
- $dom=new TXmlDocument;
- $dom->loadFromFile($this->_paramFile);
- $cache->set($cacheKey,$dom,0,new TFileCacheDependency($this->_paramFile));
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ $configFile = include $this->_paramFile;
+ else
+ {
+ $configFile=new TXmlDocument;
+ $configFile->loadFromFile($this->_paramFile);
+ }
+ $cache->set($cacheKey,$configFile,0,new TFileCacheDependency($this->_paramFile));
}
}
else
{
- $dom=new TXmlDocument;
- $dom->loadFromFile($this->_paramFile);
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ $configFile = include $this->_paramFile;
+ else
+ {
+ $configFile=new TXmlDocument;
+ $configFile->loadFromFile($this->_paramFile);
+ }
}
- $this->loadParameters($dom);
+ $this->loadParameters($configFile);
}
$this->_initialized=true;
}
/**
* Loads parameters into application.
- * @param TXmlElement XML representation of the parameters
+ * @param mixed XML or PHP representation of the parameters
* @throws TConfigurationException if the parameter file format is invalid
*/
- protected function loadParameters($xmlNode)
+ protected function loadParameters($config)
{
$parameters=array();
- foreach($xmlNode->getElementsByTagName('parameter') as $node)
+ if(is_array($config))
+ {
+ foreach($config as $id => $parameter)
+ {
+ if(is_array($parameter) && isset($parameter['class']))
+ {
+ $properties = isset($parameter['properties'])?$parameter['properties']:array();
+ $parameters[$id]=array($parameter['class'],$properties);
+ }
+ else
+ {
+ $parameters[$id] = $parameter;
+ }
+ }
+ }
+ else if($config instanceof TXmlElement)
{
- $properties=$node->getAttributes();
- if(($id=$properties->remove('id'))===null)
- throw new TConfigurationException('parametermodule_parameterid_required');
- if(($type=$properties->remove('class'))===null)
+ foreach($config->getElementsByTagName('parameter') as $node)
{
- if(($value=$properties->remove('value'))===null)
- $parameters[$id]=$node;
+ $properties=$node->getAttributes();
+ if(($id=$properties->remove('id'))===null)
+ throw new TConfigurationException('parametermodule_parameterid_required');
+ if(($type=$properties->remove('class'))===null)
+ {
+ if(($value=$properties->remove('value'))===null)
+ $parameters[$id]=$node;
+ else
+ $parameters[$id]=$value;
+ }
else
- $parameters[$id]=$value;
+ $parameters[$id]=array($type,$properties->toArray());
}
- else
- $parameters[$id]=array($type,$properties->toArray());
}
-
+
$appParams=$this->getApplication()->getParameters();
foreach($parameters as $id=>$parameter)
{
@@ -136,7 +168,7 @@ class TParameterModule extends TModule
{
if($this->_initialized)
throw new TInvalidOperationException('parametermodule_parameterfile_unchangeable');
- else if(($this->_paramFile=Prado::getPathOfNamespace($value,self::PARAM_FILE_EXT))===null || !is_file($this->_paramFile))
+ else if(($this->_paramFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null || !is_file($this->_paramFile))
throw new TConfigurationException('parametermodule_parameterfile_invalid',$value);
}
}