summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorxue <>2007-08-19 21:16:57 +0000
committerxue <>2007-08-19 21:16:57 +0000
commit1dc53969d1e4db7248db9892e10f0cad25b5205d (patch)
tree6132e816b0206ba987ef2bdda156afc1fc6a117d /framework
parent45016cc46902d78333dc7c3a9348c4d0f8c45048 (diff)
refactored app config loading code.
Diffstat (limited to 'framework')
-rw-r--r--framework/Exceptions/messages.txt5
-rw-r--r--framework/TApplication.php180
2 files changed, 130 insertions, 55 deletions
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt
index f4b5678f..6fc7360a 100644
--- a/framework/Exceptions/messages.txt
+++ b/framework/Exceptions/messages.txt
@@ -44,6 +44,11 @@ appconfig_serviceid_required = Application configuration <service> element mus
appconfig_servicetype_required = Application configuration <service id="{0}"> must have a "class" attribute.
appconfig_parameterid_required = Application configuration <parameter> element must have an "id" attribute.
appconfig_includefile_required = Application configuration <include> element must have a "file" attribute.
+appconfig_paths_invalid = Application configuration <paths> cannot contain element <{0}>.
+appconfig_modules_invalid = Application configuration <modules> cannot contain element <{0}>.
+appconfig_services_invalid = Application configuration <services> cannot contain element <{0}>.
+appconfig_parameters_invalid = Application configuration <parameters> cannot contain element <{0}>.
+appconfig_tag_invalid = Application configuration cannot contain element <{0}>.
securitymanager_validationkey_invalid = TSecurityManager.ValidationKey must not be empty.
securitymanager_encryptionkey_invalid = TSecurityManager.EncryptionKey must not be empty.
diff --git a/framework/TApplication.php b/framework/TApplication.php
index 5ae86a39..4f05fd42 100644
--- a/framework/TApplication.php
+++ b/framework/TApplication.php
@@ -1215,85 +1215,149 @@ class TApplicationConfiguration extends TComponent
$this->_empty=false;
}
- // paths
- if(($pathsNode=$dom->getElementByTagName('paths'))!==null)
+ foreach($dom->getElements() as $element)
{
- foreach($pathsNode->getElementsByTagName('alias') as $aliasNode)
+ switch($element->getTagName())
{
- if(($id=$aliasNode->getAttribute('id'))!==null && ($path=$aliasNode->getAttribute('path'))!==null)
+ case 'paths':
+ $this->loadPathsXml($element,$configPath);
+ break;
+ case 'modules':
+ $this->loadModulesXml($element,$configPath);
+ break;
+ case 'services':
+ $this->loadServicesXml($element,$configPath);
+ break;
+ case 'parameters':
+ $this->loadParametersXml($element,$configPath);
+ break;
+ case 'include':
+ $this->loadExternalXml($element,$configPath);
+ break;
+ default:
+ //throw new TConfigurationException('appconfig_tag_invalid',$element->getTagName());
+ break;
+ }
+ }
+ }
+
+ /**
+ * Loads the paths XML node.
+ * @param TXmlElement the paths XML node
+ * @param string the context path (for specifying relative paths)
+ */
+ protected function loadPathsXml($pathsNode,$configPath)
+ {
+ foreach($pathsNode->getElements() as $element)
+ {
+ switch($element->getTagName())
+ {
+ case 'alias':
{
- $path=str_replace('\\','/',$path);
- if(preg_match('/^\\/|.:\\/|.:\\\\/',$path)) // if absolute path
- $p=realpath($path);
+ if(($id=$element->getAttribute('id'))!==null && ($path=$element->getAttribute('path'))!==null)
+ {
+ $path=str_replace('\\','/',$path);
+ if(preg_match('/^\\/|.:\\/|.:\\\\/',$path)) // if absolute path
+ $p=realpath($path);
+ else
+ $p=realpath($configPath.DIRECTORY_SEPARATOR.$path);
+ if($p===false || !is_dir($p))
+ throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path);
+ if(isset($this->_aliases[$id]))
+ throw new TConfigurationException('appconfig_alias_redefined',$id);
+ $this->_aliases[$id]=$p;
+ }
else
- $p=realpath($configPath.DIRECTORY_SEPARATOR.$path);
- if($p===false || !is_dir($p))
- throw new TConfigurationException('appconfig_aliaspath_invalid',$id,$path);
- if(isset($this->_aliases[$id]))
- throw new TConfigurationException('appconfig_alias_redefined',$id);
- $this->_aliases[$id]=$p;
+ throw new TConfigurationException('appconfig_alias_invalid');
+ $this->_empty=false;
+ break;
}
- else
- throw new TConfigurationException('appconfig_alias_invalid');
- $this->_empty=false;
- }
- foreach($pathsNode->getElementsByTagName('using') as $usingNode)
- {
- if(($namespace=$usingNode->getAttribute('namespace'))!==null)
- $this->_usings[]=$namespace;
- else
- throw new TConfigurationException('appconfig_using_invalid');
- $this->_empty=false;
+ case 'using':
+ {
+ if(($namespace=$element->getAttribute('namespace'))!==null)
+ $this->_usings[]=$namespace;
+ else
+ throw new TConfigurationException('appconfig_using_invalid');
+ $this->_empty=false;
+ break;
+ }
+ default:
+ throw new TConfigurationException('appconfig_paths_invalid',$tagName);
}
}
+ }
- // application modules
- if(($modulesNode=$dom->getElementByTagName('modules'))!==null)
+ /**
+ * Loads the modules XML node.
+ * @param TXmlElement the modules XML node
+ * @param string the context path (for specifying relative paths)
+ */
+ protected function loadModulesXml($modulesNode,$configPath)
+ {
+ foreach($modulesNode->getElements() as $element)
{
- foreach($modulesNode->getElementsByTagName('module') as $node)
+ if($element->getTagName()==='module')
{
- $properties=$node->getAttributes();
+ $properties=$element->getAttributes();
$id=$properties->itemAt('id');
$type=$properties->remove('class');
if($type===null)
throw new TConfigurationException('appconfig_moduletype_required',$id);
- $node->setParent(null);
+ $element->setParent(null);
if($id===null)
- $this->_modules[]=array($type,$properties->toArray(),$node);
+ $this->_modules[]=array($type,$properties->toArray(),$element);
else
- $this->_modules[$id]=array($type,$properties->toArray(),$node);
+ $this->_modules[$id]=array($type,$properties->toArray(),$element);
$this->_empty=false;
}
+ else
+ throw new TConfigurationException('appconfig_modules_invalid',$element->getTagName());
}
+ }
- // services
- if(($servicesNode=$dom->getElementByTagName('services'))!==null)
+ /**
+ * Loads the services XML node.
+ * @param TXmlElement the services XML node
+ * @param string the context path (for specifying relative paths)
+ */
+ protected function loadServicesXml($servicesNode,$configPath)
+ {
+ foreach($servicesNode->getElements() as $element)
{
- foreach($servicesNode->getElementsByTagName('service') as $node)
+ if($element->getTagName()==='service')
{
- $properties=$node->getAttributes();
+ $properties=$element->getAttributes();
if(($id=$properties->itemAt('id'))===null)
throw new TConfigurationException('appconfig_serviceid_required');
if(($type=$properties->remove('class'))===null)
throw new TConfigurationException('appconfig_servicetype_required',$id);
- $node->setParent(null);
- $this->_services[$id]=array($type,$properties->toArray(),$node);
+ $element->setParent(null);
+ $this->_services[$id]=array($type,$properties->toArray(),$element);
$this->_empty=false;
}
+ else
+ throw new TConfigurationException('appconfig_services_invalid',$element->getTagName());
}
+ }
- // parameters
- if(($parametersNode=$dom->getElementByTagName('parameters'))!==null)
+ /**
+ * Loads the parameters XML node.
+ * @param TXmlElement the parameters XML node
+ * @param string the context path (for specifying relative paths)
+ */
+ protected function loadParametersXml($parametersNode,$configPath)
+ {
+ foreach($parametersNode->getElements() as $element)
{
- foreach($parametersNode->getElementsByTagName('parameter') as $node)
+ if($element->getTagName()==='parameters')
{
- $properties=$node->getAttributes();
+ $properties=$element->getAttributes();
if(($id=$properties->remove('id'))===null)
throw new TConfigurationException('appconfig_parameterid_required');
if(($type=$properties->remove('class'))===null)
{
if(($value=$properties->remove('value'))===null)
- $this->_parameters[$id]=$node;
+ $this->_parameters[$id]=$element;
else
$this->_parameters[$id]=$value;
}
@@ -1301,24 +1365,30 @@ class TApplicationConfiguration extends TComponent
$this->_parameters[$id]=array($type,$properties->toArray());
$this->_empty=false;
}
- }
-
- // external configurations
- foreach($dom->getElementsByTagName('include') as $node)
- {
- if(($when=$node->getAttribute('when'))===null)
- $when=true;
- if(($filePath=$node->getAttribute('file'))===null)
- throw new TConfigurationException('appconfig_includefile_required');
- if(isset($this->_includes[$filePath]))
- $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')';
else
- $this->_includes[$filePath]=$when;
- $this->_empty=false;
+ throw new TConfigurationException('appconfig_parameters_invalid',$element->getTagName());
}
}
/**
+ * Loads the external XML configurations.
+ * @param TXmlElement the application DOM element
+ * @param string the context path (for specifying relative paths)
+ */
+ protected function loadExternalXml($includeNode,$configPath)
+ {
+ if(($when=$includeNode->getAttribute('when'))===null)
+ $when=true;
+ if(($filePath=$includeNode->getAttribute('file'))===null)
+ throw new TConfigurationException('appconfig_includefile_required');
+ if(isset($this->_includes[$filePath]))
+ $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')';
+ else
+ $this->_includes[$filePath]=$when;
+ $this->_empty=false;
+ }
+
+ /**
* Returns list of page initial property values.
* Each array element represents a single property with the key
* being the property name and the value the initial property value.