summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
Diffstat (limited to 'framework')
-rw-r--r--framework/Exceptions/messages.txt6
-rw-r--r--framework/Security/TUserManager.php22
-rw-r--r--framework/Util/TParameterModule.php131
-rw-r--r--framework/Web/Services/TPageService.php6
4 files changed, 151 insertions, 14 deletions
diff --git a/framework/Exceptions/messages.txt b/framework/Exceptions/messages.txt
index b4f81c8b..dd680098 100644
--- a/framework/Exceptions/messages.txt
+++ b/framework/Exceptions/messages.txt
@@ -273,4 +273,8 @@ texthighlighter_stylesheet_invalid = Unable to find the stylesheet file for TTe
hotspotcollection_hotspot_required = THotSpotCollection can only accept instance of THotSpot or its derived classes.
htmlarea_textmode_readonly = THtmlArea.TextMode is read-only.
-htmlarea_tarfile_invalid = THtmlArea is unable to locate the TinyMCE tar file. \ No newline at end of file
+htmlarea_tarfile_invalid = THtmlArea is unable to locate the TinyMCE tar file.
+
+parametermodule_parameterfile_unchangeable = TParameterModule.ParameterFile is not changeable because the module is already initialized.
+parametermodule_parameterfile_invalid = TParameterModule.ParameterFile '{0}' is invalid. Make sure it is in namespace format and the file extension is '.xml'.
+parametermodule_parameterid_required = Parameter element must have 'id' attribute. \ No newline at end of file
diff --git a/framework/Security/TUserManager.php b/framework/Security/TUserManager.php
index 5ad582e1..5bd18d0c 100644
--- a/framework/Security/TUserManager.php
+++ b/framework/Security/TUserManager.php
@@ -168,12 +168,19 @@ class TUser extends TComponent implements IUser
*
* TUserManager manages a static list of users {@link TUser}.
* The user information is specified via module configuration using the following XML syntax,
+ * <code>
* <module id="users" class="System.Security.TUserManager" PasswordMode="Clear">
* <user name="Joe" password="demo" />
* <user name="John" password="demo" />
* <role name="Administrator" users="John" />
* <role name="Writer" users="Joe,John" />
* </module>
+ * </code>
+ *
+ * In addition, user information can also be loaded from an external file
+ * specified by {@link setUserFile UserFile} property. Note, the property
+ * only accepts a file path in namespace format. The user file format is
+ * similar to the above sample.
*
* The user passwords may be specified as clear text, SH1 or MD5 hashed by setting
* {@link setPasswordMode PasswordMode} as <b>Clear</b>, <b>SH1</b> or <b>MD5</b>.
@@ -228,18 +235,13 @@ class TUserManager extends TModule
*/
public function init($config)
{
+ $this->loadUserData($config);
if($this->_userFile!==null)
{
- if(is_file($this->_userFile))
- {
- $dom=new TXmlDocument;
- $dom->loadFromFile($this->_userFile);
- $this->loadUserData($dom);
- }
- else
- throw new TConfigurationException('usermanager_userfile_invalid',$this->_userFile);
+ $dom=new TXmlDocument;
+ $dom->loadFromFile($this->_userFile);
+ $this->loadUserData($dom);
}
- $this->loadUserData($config);
$this->_initialized=true;
}
@@ -287,7 +289,7 @@ class TUserManager extends TModule
{
if($this->_initialized)
throw new TInvalidOperationException('usermanager_userfile_unchangeable');
- else if(($this->_userFile=Prado::getPathOfNamespace($value,self::USER_FILE_EXT))===null)
+ else if(($this->_userFile=Prado::getPathOfNamespace($value,self::USER_FILE_EXT))===null || !is_file($this->_userFile))
throw new TConfigurationException('usermanager_userfile_invalid',$value);
}
diff --git a/framework/Util/TParameterModule.php b/framework/Util/TParameterModule.php
new file mode 100644
index 00000000..a72e8fe8
--- /dev/null
+++ b/framework/Util/TParameterModule.php
@@ -0,0 +1,131 @@
+<?php
+/**
+ * TParameterModule class
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @link http://www.pradosoft.com/
+ * @copyright Copyright &copy; 2005 PradoSoft
+ * @license http://www.pradosoft.com/license/
+ * @version $Revision: $ $Date: $
+ * @package System.Util
+ */
+
+/**
+ * TParameterModule class
+ *
+ * TParameterModule enables loading application parameters from external
+ * storage other than the application configuration.
+ * To load parameters from an XML file, configure the module by setting
+ * its {@link setParameterFile ParameterFile} property.
+ * Note, the property only accepts a file path in namespace format with
+ * file extension being '.xml'. The file format is as follows, which is
+ * similar to the parameter portion in an application configuration,
+ * <code>
+ * <parameters>
+ * <parameter id="param1" value="paramValue1" />
+ * <parameter id="param2" Property1="Value1" Property2="Value2" ... />
+ * </parameters>
+ * </code>
+ *
+ * In addition, any content enclosed within the module tag is also treated
+ * as parameters, e.g.,
+ * <code>
+ * <module class="System.Util.TParameterModule">
+ * <parameter id="param1" value="paramValue1" />
+ * <parameter id="param2" Property1="Value1" Property2="Value2" ... />
+ * </module>
+ * </code>
+ *
+ * If a parameter is defined both in the external file and within the module
+ * tag, the former takes precedence.
+ *
+ * @author Qiang Xue <qiang.xue@gmail.com>
+ * @version $Revision: $ $Date: $
+ * @package System.Util
+ * @since 3.0
+ */
+class TParameterModule extends TModule
+{
+ 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
+ */
+ public function init($config)
+ {
+ $this->loadParameters($config);
+ if($this->_paramFile!==null)
+ {
+ $dom=new TXmlDocument;
+ $dom->loadFromFile($this->_paramFile);
+ $this->loadParameters($dom);
+ }
+ $this->_initialized=true;
+ }
+
+ /**
+ * Loads parameters into application.
+ * @param TXmlElement XML representation of the parameters
+ * @throws TConfigurationException if the parameter file format is invalid
+ */
+ protected function loadParameters($xmlNode)
+ {
+ $parameters=array();
+ foreach($xmlNode->getElementsByTagName('parameter') as $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]=array($type,$properties->toArray());
+ }
+
+ $appParams=$this->getApplication()->getParameters();
+ foreach($parameters as $id=>$parameter)
+ {
+ if(is_array($parameter))
+ {
+ $component=Prado::createComponent($parameter[0]);
+ foreach($parameter[1] as $name=>$value)
+ $component->setSubProperty($name,$value);
+ $appParams->add($id,$component);
+ }
+ else
+ $appParams->add($id,$parameter);
+ }
+ }
+
+ /**
+ * @return string the parameter file path
+ */
+ public function getParameterFile()
+ {
+ return $this->_paramFile;
+ }
+
+ /**
+ * @param string the parameter file path. It must be in namespace format
+ * and the file extension is '.xml'.
+ * @throws TInvalidOperationException if the module is initialized
+ * @throws TConfigurationException if the file is invalid
+ */
+ public function setParameterFile($value)
+ {
+ 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))
+ throw new TConfigurationException('parametermodule_parameterfile_invalid',$value);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php
index 022c1286..8590540f 100644
--- a/framework/Web/Services/TPageService.php
+++ b/framework/Web/Services/TPageService.php
@@ -170,15 +170,15 @@ class TPageService extends TService
$parameters=$application->getParameters();
foreach($pageConfig->getParameters() as $id=>$parameter)
{
- if(is_string($parameter))
- $parameters->add($id,$parameter);
- else
+ if(is_array($parameter))
{
$component=Prado::createComponent($parameter[0]);
foreach($parameter[1] as $name=>$value)
$component->setSubProperty($name,$value);
$parameters->add($id,$component);
}
+ else
+ $parameters->add($id,$parameter);
}
// load modules specified in page directory config