summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitattributes5
-rw-r--r--demos/address-book/index_php.php27
-rw-r--r--demos/address-book/protected/application.php57
-rw-r--r--demos/personal/index_php.php13
-rw-r--r--demos/personal/protected/Pages/Layout.tpl2
-rw-r--r--demos/personal/protected/Pages/config.php18
-rw-r--r--demos/personal/protected/application.php44
-rw-r--r--demos/personal/protected/application.xml7
-rw-r--r--framework/Data/TDataSourceConfig.php28
-rw-r--r--framework/PradoBase.php6
-rw-r--r--framework/Security/TUserManager.php63
-rw-r--r--framework/TApplication.php231
-rw-r--r--framework/Web/Services/TPageService.php156
-rw-r--r--framework/Web/Services/TSoapService.php38
14 files changed, 637 insertions, 58 deletions
diff --git a/.gitattributes b/.gitattributes
index dd98e463..3b7e0920 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -695,7 +695,9 @@ buildscripts/wikibuilder/dumpHTML.php -text
buildscripts/wikibuilder/external.png -text
buildscripts/wikibuilder/main.css -text
demos/address-book/index.php -text
+demos/address-book/index_php.php -text
demos/address-book/protected/.htaccess -text
+demos/address-book/protected/application.php -text
demos/address-book/protected/application.xml -text
demos/address-book/protected/pages/AddressProvider.php -text
demos/address-book/protected/pages/AddressRecord.php -text
@@ -1115,6 +1117,7 @@ demos/northwind-db/protected/pages/NorthwindCrud.page -text
demos/northwind-db/protected/pages/NorthwindCrud.php -text
demos/northwind-db/protected/pages/northwind.gif -text
demos/personal/index.php -text
+demos/personal/index_php.php -text
demos/personal/protected/.htaccess -text
demos/personal/protected/Common/LoginPortlet.php -text
demos/personal/protected/Common/LoginPortlet.tpl -text
@@ -1130,7 +1133,9 @@ demos/personal/protected/Pages/Register.php -text
demos/personal/protected/Pages/Resume.page -text
demos/personal/protected/Pages/Settings.page -text
demos/personal/protected/Pages/UserLogin.page -text
+demos/personal/protected/Pages/config.php -text
demos/personal/protected/Pages/config.xml -text
+demos/personal/protected/application.php -text
demos/personal/protected/application.xml -text
demos/personal/themes/BlueTheme/buttons.skin -text
demos/personal/themes/BlueTheme/icon_profile.gif -text
diff --git a/demos/address-book/index_php.php b/demos/address-book/index_php.php
new file mode 100644
index 00000000..17cf61ad
--- /dev/null
+++ b/demos/address-book/index_php.php
@@ -0,0 +1,27 @@
+<?php
+$frameworkPath='../../framework/prado.php';
+
+/** The directory checks may be removed if performance is required **/
+$basePath=dirname(__FILE__);
+$assetsPath=$basePath."/assets";
+$runtimePath=$basePath."/protected/runtime";
+$sqliteDbDir=$basePath."/protected/pages/";
+$sqliteDb=$sqliteDbDir.'sqlite.db';
+
+if(!is_file($frameworkPath))
+ die("Unable to find prado framework path $frameworkPath.");
+if(!is_writable($assetsPath))
+ die("Please make sure that the directory $assetsPath is writable by Web server process.");
+if(!is_writable($runtimePath))
+ die("Please make sure that the directory $runtimePath is writable by Web server process.");
+if(!is_writable($sqliteDbDir))
+ die("Please make sure that the directory $sqliteDbDir is writable by Web server process.");
+if(!is_writable($sqliteDb))
+ die("Please make sure that the file $sqliteDbDir is writable by Web server process.");
+
+require_once($frameworkPath);
+
+$application=new TApplication('protected',false,TApplication::CONFIG_TYPE_PHP);
+$application->run();
+
+?> \ No newline at end of file
diff --git a/demos/address-book/protected/application.php b/demos/address-book/protected/application.php
new file mode 100644
index 00000000..1a95e46e
--- /dev/null
+++ b/demos/address-book/protected/application.php
@@ -0,0 +1,57 @@
+<?php
+
+return array(
+ 'application' => array(
+ 'id' => 'address-book',
+ 'mode' => 'Debug',
+ ),
+ 'paths' => array(
+ 'using'=>array(
+ 'System.Data.*',
+ 'System.Security.*',
+ 'System.Data.ActiveRecord.*',
+ 'System.Web.Services.*',
+ ),
+ 'aliases'=>array(
+ 'myapp' => '/Users/carlgmathisen/Sites/prado3/branch3.2/demos/personal/protected',
+ )
+ ),
+ 'modules' => array(
+ 'sqlite-db' => array(
+ 'class' => 'TActiveRecordConfig',
+ 'database' => array(
+ 'ConnectionString' => 'sqlite:./protected/pages/sqlite.db',
+ ),
+ ),
+ 'users' => array(
+ 'class' => 'TUserManager',
+ 'properties' => array(
+ 'PasswordMode' => 'Clear',
+ ),
+ 'users' => array(
+ array(
+ 'name'=>'demo',
+ 'password'=>'demo'
+ ),
+ ),
+ ),
+ 'auth' => array(
+ 'class' => 'System.Security.TAuthManager',
+ 'properties' => array(
+ 'userManager' => 'users',
+ 'loginPage' => 'Login',
+ ),
+ ),
+ ),
+ 'services' => array(
+ 'soap' => array(
+ 'class' => 'TSoapService',
+ 'address-book' => array(
+ 'properties' => array(
+ 'provider' => 'Application.pages.AddressProvider',
+ 'ClassMaps' => 'AddressRecord',
+ ),
+ ),
+ ),
+ ),
+); \ No newline at end of file
diff --git a/demos/personal/index_php.php b/demos/personal/index_php.php
new file mode 100644
index 00000000..cf57d82d
--- /dev/null
+++ b/demos/personal/index_php.php
@@ -0,0 +1,13 @@
+<?php
+
+$basePath=dirname(__FILE__);
+$frameworkPath=$basePath.'/../../framework/prado.php';
+$assetsPath=$basePath.'/assets';
+
+if(!is_writable($assetsPath))
+ die("Please make sure that the directory $assetsPath is writable by Web server process.");
+
+require_once($frameworkPath);
+
+$application=new TApplication('protected',false,TApplication::CONFIG_TYPE_PHP);
+$application->run(); \ No newline at end of file
diff --git a/demos/personal/protected/Pages/Layout.tpl b/demos/personal/protected/Pages/Layout.tpl
index 3ffb5306..d650a689 100644
--- a/demos/personal/protected/Pages/Layout.tpl
+++ b/demos/personal/protected/Pages/Layout.tpl
@@ -8,7 +8,7 @@
<div class="header">
<h1>Your Name Here</h1>
-<h2>My Personal Site</h2>
+<h2><%$siteName%></h2>
<div class="mainmenu">
<com:MainMenu />
diff --git a/demos/personal/protected/Pages/config.php b/demos/personal/protected/Pages/config.php
new file mode 100644
index 00000000..7a6c9a6c
--- /dev/null
+++ b/demos/personal/protected/Pages/config.php
@@ -0,0 +1,18 @@
+<?php
+return array(
+ 'authorization' => array(
+ array(
+ 'action' => 'deny',
+ 'properties' => array(
+ 'pages' => 'Settings',
+ 'users' => '?',
+ ),
+ ),
+ ),
+ 'pages' => array(
+ 'properties' => array(
+ 'MasterClass' => 'Application.Pages.Layout',
+ 'Theme' => 'White',
+ ),
+ ),
+); \ No newline at end of file
diff --git a/demos/personal/protected/application.php b/demos/personal/protected/application.php
new file mode 100644
index 00000000..11ad1ef8
--- /dev/null
+++ b/demos/personal/protected/application.php
@@ -0,0 +1,44 @@
+<?php
+return array(
+ 'application' => array(
+ 'id' => 'personal',
+ 'mode' => 'Debug',
+ ),
+ 'paths' => array(
+ 'using'=>array('Application.common.*'),
+ 'aliases'=>array(
+ 'myapp' => '/Users/carlgmathisen/Sites/prado3/branch3.2/demos/personal/protected',
+ )
+ ),
+ 'modules' => array(
+ ),
+ 'services' => array(
+ 'page' => array(
+ 'class' => 'TPageService',
+ 'properties' => array(
+ 'basePath' => 'Application.Pages',
+ ),
+ 'modules' => array(
+ 'users' => array(
+ 'class' => 'System.Security.TUserManager',
+ 'properties' => array(
+ 'passwordMode' => 'Clear',
+ ),
+ 'users' => array(
+ array('name'=>'demo','password'=>'demo'),
+ ),
+ ), // users
+ 'auth' => array(
+ 'class' => 'System.Security.TAuthManager',
+ 'properties' => array(
+ 'userManager' => 'users',
+ 'loginPage' => 'UserLogin',
+ ),
+ ),
+ ),
+ ),
+ ),
+ 'parameters' => array(
+ 'siteName' => 'My Personal Site (PHP Config)',
+ )
+); \ No newline at end of file
diff --git a/demos/personal/protected/application.xml b/demos/personal/protected/application.xml
index d2affe24..e9115f29 100644
--- a/demos/personal/protected/application.xml
+++ b/demos/personal/protected/application.xml
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
-<application id="personal" mode="Normal">
+<application id="personal" mode="Debug">
<paths>
<using namespace="Application.Common.*" />
</paths>
@@ -33,4 +33,7 @@
</modules>
</service>
</services>
-</application> \ No newline at end of file
+ <parameters>
+ <parameter id="siteName" value="My Personal Site" />
+ </parameters>
+</application>
diff --git a/framework/Data/TDataSourceConfig.php b/framework/Data/TDataSourceConfig.php
index a02c68a1..804ea848 100644
--- a/framework/Data/TDataSourceConfig.php
+++ b/framework/Data/TDataSourceConfig.php
@@ -1,10 +1,10 @@
-<?php
+<?php
/**
* TDataSourceConfig class file.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]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.Data
@@ -58,11 +58,23 @@ class TDataSourceConfig extends TModule
*/
public function init($xml)
{
- if($prop=$xml->getElementByTagName('database'))
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
{
- $db=$this->getDbConnection();
- foreach($prop->getAttributes() as $name=>$value)
- $db->setSubproperty($name,$value);
+ if(isset($xml['database']) && is_array($xml['database']))
+ {
+ $db=$this->getDbConnection();
+ foreach($xml['database'] as $name=>$value)
+ $db->setSubProperty($name,$value);
+ }
+ }
+ else
+ {
+ if($prop=$xml->getElementByTagName('database'))
+ {
+ $db=$this->getDbConnection();
+ foreach($prop->getAttributes() as $name=>$value)
+ $db->setSubproperty($name,$value);
+ }
}
}
@@ -153,5 +165,5 @@ class TDataSourceConfig extends TModule
throw new TConfigurationException('datasource_dbconnection_invalid',$id);
}
}
-
-?>
+
+?>
diff --git a/framework/PradoBase.php b/framework/PradoBase.php
index e6a77136..15932cad 100644
--- a/framework/PradoBase.php
+++ b/framework/PradoBase.php
@@ -7,7 +7,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
@@ -66,7 +66,7 @@ class PradoBase
*/
public static function getVersion()
{
- return '3.1.3a';
+ return '3.2a';
}
/**
@@ -611,4 +611,4 @@ PradoBase::using('System.TComponent');
PradoBase::using('System.Exceptions.TException');
PradoBase::using('System.Util.TLogger');
-?>
+?>
diff --git a/framework/Security/TUserManager.php b/framework/Security/TUserManager.php
index 20b2cbb1..6326803d 100644
--- a/framework/Security/TUserManager.php
+++ b/framework/Security/TUserManager.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.Security
@@ -83,25 +83,72 @@ class TUserManager extends TModule implements IUserManager
* Initializes the module.
* This method is required by IModule and is invoked by application.
* It loads user/role information from the module configuration.
- * @param TXmlElement module configuration
+ * @param mixed module configuration
*/
public function init($config)
{
- $this->loadUserData($config);
+ $isPhp = $this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP;
+ if($isPhp)
+ $this->loadUserDataFromPhp($config);
+ else
+ $this->loadUserDataFromXml($config);
+
if($this->_userFile!==null)
{
- $dom=new TXmlDocument;
- $dom->loadFromFile($this->_userFile);
- $this->loadUserData($dom);
+ if($isPhp)
+ {
+ $this->loadUserDataFromPhp($config);
+ }
+ else
+ {
+ $dom=new TXmlDocument;
+ $dom->loadFromFile($this->_userFile);
+ $this->loadUserDataFromXml($dom);
+ }
}
$this->_initialized=true;
}
+ private function loadUserDataFromPhp($config)
+ {
+ if(isset($config['users']) && is_array($config['users']))
+ {
+ foreach($config['users'] as $user)
+ {
+ $name = trim(strtolower(isset($user['name'])?$user['name']:''));
+ $password = isset($user['password'])?$user['password']:'';
+ $this->_users[$name] = $password;
+ $roles = isset($user['roles'])?$user['roles']:'';
+ if($roles!=='')
+ {
+ foreach(explode(',',$roles) as $role)
+ {
+ if(($role=trim($role))!=='')
+ $this->_roles[$name][]=$role;
+ }
+ }
+ }
+ }
+ if(isset($config['roles']) && is_array($config['roles']))
+ {
+ foreach($config['roles'] as $role)
+ {
+ $name = isset($role['name'])?$role['name']:'';
+ $users = isset($role['users'])?$role['users']:'';
+ foreach(explode(',',$users) as $user)
+ {
+ if(($user=trim($user))!=='')
+ $this->_roles[strtolower($user)][]=$name;
+ }
+ }
+ }
+ }
+
/**
* Loads user/role information from an XML node.
* @param TXmlElement the XML node containing the user information
*/
- private function loadUserData($xmlNode)
+ private function loadUserDataFromXml($xmlNode)
{
foreach($xmlNode->getElementsByTagName('user') as $node)
{
@@ -320,4 +367,4 @@ class TUserManagerPasswordMode extends TEnumerable
const SHA1='SHA1';
}
-?>
+?>
diff --git a/framework/TApplication.php b/framework/TApplication.php
index 9677d192..d9626179 100644
--- a/framework/TApplication.php
+++ b/framework/TApplication.php
@@ -127,11 +127,28 @@ class TApplication extends TComponent
/**
* Application configuration file name
*/
- const CONFIG_FILE='application.xml';
+ const CONFIG_FILE_XML='application.xml';
/**
* File extension for external config files
*/
- const CONFIG_FILE_EXT='.xml';
+ const CONFIG_FILE_EXT_XML='.xml';
+ /**
+ * Configuration file type, application.xml and config.xml
+ */
+ const CONFIG_TYPE_XML = 'xml';
+ /**
+ * Application configuration file name
+ */
+ const CONFIG_FILE_PHP='application.php';
+ /**
+ * File extension for external config files
+ */
+ const CONFIG_FILE_EXT_PHP='.php';
+ /**
+ * Configuration file type, application.php and config.php
+ */
+ const CONFIG_TYPE_PHP = 'php';
+
/**
* Runtime directory name
*/
@@ -201,6 +218,14 @@ class TApplication extends TComponent
*/
private $_configFile;
/**
+ * @var string configuration file extension
+ */
+ private $_configFileExt;
+ /**
+ * @var string configuration type
+ */
+ private $_configType;
+ /**
* @var string application base path
*/
private $_basePath;
@@ -287,11 +312,11 @@ class TApplication extends TComponent
* @param boolean whether to cache application configuration. Defaults to true.
* @throws TConfigurationException if configuration file cannot be read or the runtime path is invalid.
*/
- public function __construct($basePath='protected',$cacheConfig=true)
+ public function __construct($basePath='protected',$cacheConfig=true, $configType=self::CONFIG_TYPE_XML)
{
// register application as a singleton
Prado::setApplication($this);
-
+ $this->setConfigurationType($configType);
$this->resolvePaths($basePath);
if($cacheConfig)
@@ -319,8 +344,8 @@ class TApplication extends TComponent
// determine configuration path and file
if(empty($basePath) || ($basePath=realpath($basePath))===false)
throw new TConfigurationException('application_basepath_invalid',$basePath);
- if(is_file($basePath.DIRECTORY_SEPARATOR.self::CONFIG_FILE))
- $configFile=$basePath.DIRECTORY_SEPARATOR.self::CONFIG_FILE;
+ if(is_file($basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName()))
+ $configFile=$basePath.DIRECTORY_SEPARATOR.$this->getConfigurationFileName();
else if(is_file($basePath))
{
$configFile=$basePath;
@@ -541,6 +566,49 @@ class TApplication extends TComponent
$this->_configFile=$value;
}
+ public function getConfigurationType()
+ {
+ return $this->_configType;
+ }
+
+ public function setConfigurationType($value)
+ {
+ $this->_configType = $value;
+ }
+
+ public function getConfigurationFileExt()
+ {
+ if($this->_configFileExt===null)
+ {
+ switch($this->_configType)
+ {
+ case TApplication::CONFIG_TYPE_PHP:
+ $this->_configFileExt = TApplication::CONFIG_FILE_EXT_PHP;
+ break;
+ default:
+ $this->_configFileExt = TApplication::CONFIG_FILE_EXT_XML;
+ }
+ }
+ return $this->_configFileExt;
+ }
+
+ public function getConfigurationFileName()
+ {
+ static $fileName;
+ if($fileName == null)
+ {
+ switch($this->_configType)
+ {
+ case TApplication::CONFIG_TYPE_PHP:
+ $fileName = TApplication::CONFIG_FILE_PHP;
+ break;
+ default:
+ $fileName = TApplication::CONFIG_FILE_XML;
+ }
+ }
+ return $fileName;
+ }
+
/**
* @return string the directory storing cache data and application-level persistent data. (absolute path)
*/
@@ -890,7 +958,7 @@ class TApplication extends TComponent
$condition=$this->evaluateExpression($condition);
if($condition)
{
- if(($path=Prado::getPathOfNamespace($filePath,self::CONFIG_FILE_EXT))===null || !is_file($path))
+ if(($path=Prado::getPathOfNamespace($filePath,$this->getConfigurationFileExt()))===null || !is_file($path))
throw new TConfigurationException('application_includefile_invalid',$filePath);
$c=new TApplicationConfiguration;
$c->loadFromFile($path);
@@ -958,7 +1026,10 @@ class TApplication extends TComponent
if($configElement!==null)
{
$config=new TApplicationConfiguration;
- $config->loadFromXml($configElement,$this->getBasePath());
+ if($this->getConfigurationType()==self::CONFIG_TYPE_PHP)
+ $config->loadFromPhp($configElement,$this->getBasePath());
+ else
+ $config->loadFromXml($configElement,$this->getBasePath());
$this->applyConfiguration($config,true);
}
@@ -1188,9 +1259,17 @@ class TApplicationConfiguration extends TComponent
*/
public function loadFromFile($fname)
{
- $dom=new TXmlDocument;
- $dom->loadFromFile($fname);
- $this->loadFromXml($dom,dirname($fname));
+ if(Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ $fcontent = include $fname;
+ $this->loadFromPhp($fcontent,dirname($fname));
+ }
+ else
+ {
+ $dom=new TXmlDocument;
+ $dom->loadFromFile($fname);
+ $this->loadFromXml($dom,dirname($fname));
+ }
}
/**
@@ -1201,6 +1280,34 @@ class TApplicationConfiguration extends TComponent
return $this->_empty;
}
+ public function loadFromPhp($config, $configPath)
+ {
+ // application properties
+ if(isset($config['application']))
+ {
+ foreach($config['application'] as $name=>$value)
+ {
+ $this->_properties[$name]=$value;
+ }
+ $this->_empty = false;
+ }
+
+ if(isset($config['paths']) && is_array($config['paths']))
+ $this->loadPathsPhp($config['paths'],$configPath);
+
+ if(isset($config['modules']) && is_array($config['modules']))
+ $this->loadModulesPhp($config['modules'],$configPath);
+
+ if(isset($config['services']) && is_array($config['services']))
+ $this->loadServicesPhp($config['services'],$configPath);
+
+ if(isset($config['parameters']) && is_array($config['parameters']))
+ $this->loadParametersPhp($config['parameters'], $configPath);
+
+ if(isset($config['includes']) && is_array($config['includes']))
+ $this->loadExternalXml($config['includes'],$configPath);
+ }
+
/**
* Parses the application configuration given in terms of a TXmlElement.
* @param TXmlElement the XML element
@@ -1241,6 +1348,34 @@ class TApplicationConfiguration extends TComponent
}
}
+ protected function loadPathsPhp($pathsNode, $configPath)
+ {
+ if(isset($pathsNode['aliases']) && is_array($pathsNode['aliases']))
+ {
+ foreach($pathsNode['aliases'] as $id=>$path)
+ {
+ $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;
+ }
+ }
+
+ if(isset($pathsNode['using']) && is_array($pathsNode['using']))
+ {
+ foreach($pathsNode['using'] as $namespace)
+ {
+ $this->_usings[] = $namespace;
+ }
+ }
+ }
+
/**
* Loads the paths XML node.
* @param TXmlElement the paths XML node
@@ -1287,6 +1422,26 @@ class TApplicationConfiguration extends TComponent
}
}
+ protected function loadModulesPhp($modulesNode, $configPath)
+ {
+ foreach($modulesNode as $id=>$module)
+ {
+ if(!isset($module['class']))
+ throw new TConfigurationException('appconfig_moduletype_required',$id);
+ $type = $module['class'];
+ unset($module['class']);
+ $properties = array();
+ if(isset($module['properties']))
+ {
+ $properties = $module['properties'];
+ unset($module['properties']);
+ }
+ $properties['id'] = $id;
+ $this->_modules[$id]=array($type,$properties,$module);
+ $this->_empty=false;
+ }
+ }
+
/**
* Loads the modules XML node.
* @param TXmlElement the modules XML node
@@ -1315,6 +1470,22 @@ class TApplicationConfiguration extends TComponent
}
}
+ protected function loadServicesPhp($servicesNode,$configPath)
+ {
+ foreach($servicesNode as $id => $service)
+ {
+ if(!isset($service['class']))
+ throw new TConfigurationException('appconfig_servicetype_required');
+ $type = $service['class'];
+ unset($service['class']);
+ $properties = isset($service['properties']) ? $service['properties'] : array();
+ unset($service['properties']);
+ $properties['id'] = $id;
+ $this->_services[$id] = array($type,$properties,$service);
+ $this->_empty = false;
+ }
+ }
+
/**
* Loads the services XML node.
* @param TXmlElement the services XML node
@@ -1340,6 +1511,28 @@ class TApplicationConfiguration extends TComponent
}
}
+ protected function loadParametersPhp($parametersNode,$configPath)
+ {
+ foreach($parametersNode as $id => $parameter)
+ {
+ if(is_array($parameter))
+ {
+ if(isset($parameter['class']))
+ {
+ $type = $parameter['class'];
+ unset($parameter['class']);
+ $properties = isset($service['properties']) ? $service['properties'] : array();
+ $properties['id'] = $id;
+ $this->_parameters[$id] = array($type,$properties);
+ }
+ }
+ else
+ {
+ $this->_parameters[$id] = $parameter;
+ }
+ }
+ }
+
/**
* Loads the parameters XML node.
* @param TXmlElement the parameters XML node
@@ -1370,6 +1563,22 @@ class TApplicationConfiguration extends TComponent
}
}
+ protected function loadExternalPhp($includeNode,$configPath)
+ {
+ foreach($includeNode as $include)
+ {
+ $when = isset($include['when'])?true:false;
+ if(!isset($include['file']))
+ throw new TConfigurationException('appconfig_includefile_required');
+ $filePath = $include['file'];
+ if(isset($this->_includes[$filePath]))
+ $this->_includes[$filePath]='('.$this->_includes[$filePath].') || ('.$when.')';
+ else
+ $$this->_includes[$filePath]=$when;
+ $this->_empty=false;
+ }
+ }
+
/**
* Loads the external XML configurations.
* @param TXmlElement the application DOM element
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php
index 1901e7b9..10c7da6e 100644
--- a/framework/Web/Services/TPageService.php
+++ b/framework/Web/Services/TPageService.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.Web.Services
@@ -78,7 +78,11 @@ class TPageService extends TService
/**
* Configuration file name
*/
- const CONFIG_FILE='config.xml';
+ const CONFIG_FILE_XML='config.xml';
+ /**
+ * Configuration file name
+ */
+ const CONFIG_FILE_PHP='config.php';
/**
* Default base path
*/
@@ -178,7 +182,7 @@ class TPageService extends TService
$condition=$this->evaluateExpression($condition);
if($condition)
{
- if(($path=Prado::getPathOfNamespace($filePath,TApplication::CONFIG_FILE_EXT))===null || !is_file($path))
+ if(($path=Prado::getPathOfNamespace($filePath,Prado::getApplication()->getConfigurationFileExt()))===null || !is_file($path))
throw new TConfigurationException('pageservice_includefile_invalid',$filePath);
$c=new TPageConfiguration($pagePath);
$c->loadFromFile($path,$configPagePath);
@@ -213,7 +217,12 @@ class TPageService extends TService
{
$pageConfig=new TPageConfiguration($pagePath);
if($config!==null)
- $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),'');
+ {
+ if($application->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ $pageConfig->loadPageConfigurationFromPhp($config,$application->getBasePath(),'');
+ else
+ $pageConfig->loadPageConfigurationFromXml($config,$application->getBasePath(),'');
+ }
$pageConfig->loadFromFiles($this->getBasePath());
}
else
@@ -249,9 +258,12 @@ class TPageService extends TService
$configCached=false;
$paths=explode('.',$pagePath);
$configPath=$this->getBasePath();
+ $fileName = $this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP
+ ? self::CONFIG_FILE_PHP
+ : self::CONFIG_FILE_XML;
foreach($paths as $path)
{
- $configFile=$configPath.DIRECTORY_SEPARATOR.self::CONFIG_FILE;
+ $configFile=$configPath.DIRECTORY_SEPARATOR.$fileName;
$currentTimestamp[$configFile]=@filemtime($configFile);
$configPath.=DIRECTORY_SEPARATOR.$path;
}
@@ -581,16 +593,19 @@ class TPageConfiguration extends TComponent
$page=array_pop($paths);
$path=$basePath;
$configPagePath='';
+ $fileName = Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP
+ ? TPageService::CONFIG_FILE_PHP
+ : TPageService::CONFIG_FILE_XML;
foreach($paths as $p)
{
- $this->loadFromFile($path.DIRECTORY_SEPARATOR.TPageService::CONFIG_FILE,$configPagePath);
+ $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath);
$path.=DIRECTORY_SEPARATOR.$p;
if($configPagePath==='')
$configPagePath=$p;
else
$configPagePath.='.'.$p;
}
- $this->loadFromFile($path.DIRECTORY_SEPARATOR.TPageService::CONFIG_FILE,$configPagePath);
+ $this->loadFromFile($path.DIRECTORY_SEPARATOR.$fileName,$configPagePath);
$this->_rules=new TAuthorizationRuleCollection($this->_rules);
}
@@ -604,11 +619,26 @@ class TPageConfiguration extends TComponent
Prado::trace("Loading page configuration file $fname",'System.Web.Services.TPageService');
if(empty($fname) || !is_file($fname))
return;
- $dom=new TXmlDocument;
- if($dom->loadFromFile($fname))
- $this->loadFromXml($dom,dirname($fname),$configPagePath);
+
+ if(Prado::getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ $fcontent = include $fname;
+ $this->loadFromPhp($fcontent,dirname($fname),$configPagePath);
+ }
else
- throw new TConfigurationException('pageserviceconf_file_invalid',$fname);
+ {
+ $dom=new TXmlDocument;
+ if($dom->loadFromFile($fname))
+ $this->loadFromXml($dom,dirname($fname),$configPagePath);
+ else
+ throw new TConfigurationException('pageserviceconf_file_invalid',$fname);
+ }
+ }
+
+ public function loadFromPhp($config,$configPath,$configPagePath)
+ {
+ $this->loadApplicationConfigurationFromPhp($config,$configPath);
+ $this->loadPageConfigurationFromPhp($config,$configPath,$configPagePath);
}
/**
@@ -624,6 +654,13 @@ class TPageConfiguration extends TComponent
$this->loadApplicationConfigurationFromXml($dom,$configPath);
$this->loadPageConfigurationFromXml($dom,$configPath,$configPagePath);
}
+
+ public function loadApplicationConfigurationFromPhp($config,$configPath)
+ {
+ $appConfig=new TApplicationConfiguration;
+ $appConfig->loadFromPhp($config,$configPath);
+ $this->_appConfigs[]=$appConfig;
+ }
/**
* Loads the configuration specific for application part
@@ -637,6 +674,99 @@ class TPageConfiguration extends TComponent
$this->_appConfigs[]=$appConfig;
}
+ public function loadPageConfigurationFromPhp($config, $configPath, $configPagePath)
+ {
+ // authorization
+ if(isset($config['authorization']) && is_array($config['authorization']))
+ {
+ $rules = array();
+ foreach($config['authorization'] as $authorization)
+ {
+ $patterns=isset($authorization['pages'])?$authorization['pages']:'';
+ $ruleApplies=false;
+ if(empty($patterns) || trim($patterns)==='*') // null or empty string
+ $ruleApplies=true;
+ else
+ {
+ foreach(explode(',',$patterns) as $pattern)
+ {
+ if(($pattern=trim($pattern))!=='')
+ {
+ // we know $configPagePath and $this->_pagePath
+ if($configPagePath!=='') // prepend the pattern with ConfigPagePath
+ $pattern=$configPagePath.'.'.$pattern;
+ if(strcasecmp($pattern,$this->_pagePath)===0)
+ {
+ $ruleApplies=true;
+ break;
+ }
+ if($pattern[strlen($pattern)-1]==='*') // try wildcard matching
+ {
+ if(strncasecmp($this->_pagePath,$pattern,strlen($pattern)-1)===0)
+ {
+ $ruleApplies=true;
+ break;
+ }
+ }
+ }
+ }
+ }
+ if($ruleApplies)
+ {
+ $action = isset($authorization['action'])?$authorization['action']:'';
+ $users = isset($authorization['users'])?$authorization['users']:'';
+ $roles = isset($authorization['roles'])?$authorization['roles']:'';
+ $verb = isset($authorization['verb'])?$authorization['verb']:'';
+ $ips = isset($authorization['ips'])?$authorization['ips']:'';
+ $rules[]=new TAuthorizationRule($action,$users,$roles,$verb,$ips);
+ }
+ }
+ }
+ // pages
+ if(isset($config['pages']) && is_array($config['pages']))
+ {
+ if(isset($config['pages']['properties']))
+ {
+ $this->_properties = array_merge($this->_properties, $config['pages']['properties']);
+ unset($config['pages']['properties']);
+ }
+ foreach($config['pages'] as $id => $page)
+ {
+ $properties = array();
+ if(isset($page['properties']))
+ {
+ $properties=$page['properties'];
+ unset($page['properties']);
+ }
+ $matching=false;
+ $id=($configPagePath==='')?$id:$configPagePath.'.'.$id;
+ if(strcasecmp($id,$this->_pagePath)===0)
+ $matching=true;
+ else if($id[strlen($id)-1]==='*') // try wildcard matching
+ $matching=strncasecmp($this->_pagePath,$id,strlen($id)-1)===0;
+ if($matching)
+ $this->_properties=array_merge($this->_properties,$properties);
+ }
+ $this->_rules=array_merge($rules,$this->_rules);
+ }
+
+ // external configurations
+ if(isset($config['includes']) && is_array($config['includes']))
+ {
+ foreach($config['includes'] as $include)
+ {
+ $when = isset($include['when'])?true:false;
+ if(!isset($include['file']))
+ throw new TConfigurationException('pageserviceconf_includefile_required');
+ $filePath = $include['file'];
+ if(isset($this->_includes[$filePath]))
+ $this->_includes[$filePath]=array($configPagePath,'('.$this->_includes[$filePath][1].') || ('.$when.')');
+ else
+ $this->_includes[$filePath]=array($configPagePath,$when);
+ }
+ }
+ }
+
/**
* Loads the configuration specific for page service.
* @param TXmlElement config xml element
@@ -721,6 +851,4 @@ class TPageConfiguration extends TComponent
$this->_includes[$filePath]=array($configPagePath,$when);
}
}
-}
-
-?>
+} \ No newline at end of file
diff --git a/framework/Web/Services/TSoapService.php b/framework/Web/Services/TSoapService.php
index 24f95a35..259fa5f8 100644
--- a/framework/Web/Services/TSoapService.php
+++ b/framework/Web/Services/TSoapService.php
@@ -148,19 +148,35 @@ class TSoapService extends TService
/**
* Loads configuration from an XML element
- * @param TXmlElement configuration node
+ * @param mixed configuration node
* @throws TConfigurationException if soap server id is not specified or duplicated
*/
- private function loadConfig($xml)
- {
- foreach($xml->getElementsByTagName('soap') as $serverXML)
+ private function loadConfig($config)
+ {
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ if(is_array($config))
+ {
+ foreach($config as $id => $server)
+ {
+ $properties = isset($server['properties'])?$server['properties']:array();
+ if(isset($this->_servers[$id]))
+ throw new TConfigurationException('soapservice_serverid_duplicated',$id);
+ $this->_servers[$id]=$properties;
+ }
+ }
+ }
+ else
{
- $properties=$serverXML->getAttributes();
- if(($id=$properties->remove('id'))===null)
- throw new TConfigurationException('soapservice_serverid_required');
- if(isset($this->_servers[$id]))
- throw new TConfigurationException('soapservice_serverid_duplicated',$id);
- $this->_servers[$id]=$properties;
+ foreach($config->getElementsByTagName('soap') as $serverXML)
+ {
+ $properties=$serverXML->getAttributes();
+ if(($id=$properties->remove('id'))===null)
+ throw new TConfigurationException('soapservice_serverid_required');
+ if(isset($this->_servers[$id]))
+ throw new TConfigurationException('soapservice_serverid_duplicated',$id);
+ $this->_servers[$id]=$properties;
+ }
}
}
@@ -221,7 +237,7 @@ class TSoapService extends TService
protected function createServer()
{
$properties=$this->_servers[$this->_serverID];
- if(($serverClass=$properties->remove('class'))===null)
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP || ($serverClass=$properties->remove('class'))===null)
$serverClass=self::DEFAULT_SOAP_SERVER;
Prado::using($serverClass);
$className=($pos=strrpos($serverClass,'.'))!==false?substr($serverClass,$pos+1):$serverClass;