diff options
Diffstat (limited to 'framework')
-rw-r--r-- | framework/Exceptions/messages/messages.txt | 8 | ||||
-rw-r--r-- | framework/I18N/TGlobalization.php | 23 | ||||
-rw-r--r-- | framework/Security/TUserManager.php | 49 | ||||
-rw-r--r-- | framework/TApplication.php | 45 | ||||
-rw-r--r-- | framework/Util/TLogRouter.php | 77 | ||||
-rw-r--r-- | framework/Util/TParameterModule.php | 76 | ||||
-rw-r--r-- | framework/Web/Services/TFeedService.php | 86 | ||||
-rw-r--r-- | framework/Web/Services/TJsonService.php | 76 | ||||
-rw-r--r-- | framework/Web/Services/TPageService.php | 10 | ||||
-rw-r--r-- | framework/Web/Services/TSoapService.php | 25 | ||||
-rw-r--r-- | framework/Web/TUrlMapping.php | 132 |
11 files changed, 440 insertions, 167 deletions
diff --git a/framework/Exceptions/messages/messages.txt b/framework/Exceptions/messages/messages.txt index fc2b63f1..ee5fc317 100644 --- a/framework/Exceptions/messages/messages.txt +++ b/framework/Exceptions/messages/messages.txt @@ -24,7 +24,7 @@ map_item_unremovable = The item cannot be removed from the map. map_data_not_iterable = Data must be either an array or an object implementing Traversable interface. map_readonly = {0} is read-only. -application_includefile_invalid = Unable to find application configuration {0}. Make sure it is in namespace format and the file ends with ".xml". +application_includefile_invalid = Unable to find application configuration {0}. Make sure it is in namespace format and the file ends with ".xml" or ".php". application_basepath_invalid = Application base path '{0}' does not exist or is not a directory. application_runtimepath_invalid = Application runtime path '{0}' does not exist or is not writable by Web server process. application_service_invalid = Service '{0}' must implement IService interface. @@ -114,7 +114,7 @@ pageservice_page_required = Page Name Required pageservice_defaultpage_unchangeable = TPageService.DefaultPage cannot be modified after the service is initialized. pageservice_basepath_unchangeable = TPageService.BasePath cannot be modified after the service is initialized. pageservice_pageclass_invalid = Page class {0} is invalid. It should be TPage or extend from TPage. -pageservice_includefile_invalid = Unable to find page service configuration {0}. Make sure it is in namespace format and the file ends with ".xml". +pageservice_includefile_invalid = Unable to find page service configuration {0}. Make sure it is in namespace format and the file ends with ".xml" or ".php". pageserviceconf_file_invalid = Unable to open page directory configuration file '{0}'. pageserviceconf_aliaspath_invalid = <alias id="{0}"> uses an invalid file path "{1}" in page directory configuration file '{2}'. @@ -315,7 +315,7 @@ htmlarea_textmode_readonly = THtmlArea.TextMode is read-only. 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_parameterfile_invalid = TParameterModule.ParameterFile '{0}' is invalid. Make sure it is in namespace format and the file extension is '.xml' or '.php'. parametermodule_parameterid_required = Parameter element must have 'id' attribute. datagridcolumn_id_invalid = {0}.ID '{1}' is invalid. Only alphanumeric and underline characters are allowed. The first character must be an alphabetic or underline character. @@ -401,7 +401,7 @@ dbtablegateway_invalid_table_info = Table must be a string or an instance of TD directorycachedependency_directory_invalid = TDirectoryCacheDependency.Directory {0} does not refer to a valid directory. cachedependencylist_cachedependency_required = Only objects implementing ICacheDependency can be added into TCacheDependencyList. -soapservice_configfile_invalid = TSoapService.ConfigFile '{0}' does not exist. Note, it has to be specified in a namespace format and the file extension must be '.xml'. +soapservice_configfile_invalid = TSoapService.ConfigFile '{0}' does not exist. Note, it has to be specified in a namespace format and the file extension must be '.xml' or '.php'. soapservice_request_invalid = SOAP server '{0}' not found. soapservice_serverid_required = <soap> element must have 'id' attribute. soapservice_serverid_duplicated = SOAP server ID '{0}' is duplicated. diff --git a/framework/I18N/TGlobalization.php b/framework/I18N/TGlobalization.php index 1d158ce9..7a7dce00 100644 --- a/framework/I18N/TGlobalization.php +++ b/framework/I18N/TGlobalization.php @@ -4,7 +4,7 @@ *
* @author Wei Zhuo<weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.I18N
@@ -62,20 +62,27 @@ class TGlobalization extends TModule * You should override this method if you want a different way of
* setting the Culture and/or Charset for your application.
* If you override this method, call parent::init($xml) first.
- * @param TXmlElement application configuration
+ * @param mixed application configuration
*/
- public function init($xml)
+ public function init($config)
{
if($this->_charset===null)
$this->_charset=$this->getDefaultCharset();
if($this->_culture===null)
$this->_culture=$this->getDefaultCulture();
- if($xml!==null)
+ if($config!==null)
{
- $translation = $xml->getElementByTagName('translation');
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ $translation = isset($config['translate'])?$config['translate']:null;
+ else
+ {
+ $t = $config->getElementByTagName('translation');
+ if($t)
+ $translation = $t->getAttributes();
+ }
if($translation)
- $this->setTranslationConfiguration($translation->getAttributes());
+ $this->setTranslationConfiguration($translation);
}
$this->getApplication()->setGlobalization($this);
}
@@ -165,9 +172,9 @@ class TGlobalization extends TModule * $config['marker'] = '@@'; // surround untranslated text with '@@'
* </code>
* Throws exception is source is not found.
- * @param TMap configuration options
+ * @param TMap|array configuration options
*/
- protected function setTranslationConfiguration(TMap $config)
+ protected function setTranslationConfiguration($config)
{
if($config['type'] == 'XLIFF' || $config['type'] == 'gettext')
{
diff --git a/framework/Security/TUserManager.php b/framework/Security/TUserManager.php index dbaa5ffb..878ca864 100644 --- a/framework/Security/TUserManager.php +++ b/framework/Security/TUserManager.php @@ -29,6 +29,26 @@ Prado::using('System.Security.TUser'); * </module>
* </code>
*
+ * PHP configuration style:
+ * <code>
+ * array(
+ * 'users' => array(
+ * 'class' => 'System.Security.TUserManager',
+ * 'properties' => array(
+ * 'PasswordMode' => 'Clear',
+ * ),
+ * 'users' => array(
+ * array('name'=>'Joe','password'=>'demo'),
+ * array('name'=>'John','password'=>'demo'),
+ * ),
+ * 'roles' => array(
+ * array('name'=>'Administrator','users'=>'John'),
+ * array('name'=>'Writer','users'=>'Joe,John'),
+ * ),
+ * ),
+ * )
+ * </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
@@ -43,6 +63,7 @@ Prado::using('System.Security.TUser'); * how users are authenticated and authorized in a Prado application.
*
* @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Carl Mathisen <carl@kamikazemedia.no>
* @version $Id$
* @package System.Security
* @since 3.0
@@ -87,17 +108,13 @@ class TUserManager extends TModule implements IUserManager */
public function init($config)
{
- $isPhp = $this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP;
- if($isPhp)
- $this->loadUserDataFromPhp($config);
- else
- $this->loadUserDataFromXml($config);
-
+ $this->loadUserData($config);
if($this->_userFile!==null)
{
- if($isPhp)
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
{
- $this->loadUserDataFromPhp($config);
+ $userFile = include $this->_userFile;
+ $this->loadUserDataFromPhp($userFile);
}
else
{
@@ -108,7 +125,23 @@ class TUserManager extends TModule implements IUserManager }
$this->_initialized=true;
}
+
+ /*
+ * Loads user/role information
+ * @param mixed the variable containing the user information
+ */
+ private function loadUserData($config)
+ {
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ $this->loadUserDataFromPhp($config);
+ else
+ $this->loadUserDataFromXml($config);
+ }
+ /**
+ * Loads user/role information from an php array.
+ * @param array the array containing the user information
+ */
private function loadUserDataFromPhp($config)
{
if(isset($config['users']) && is_array($config['users']))
diff --git a/framework/TApplication.php b/framework/TApplication.php index e690aa96..d9298d90 100644 --- a/framework/TApplication.php +++ b/framework/TApplication.php @@ -148,7 +148,6 @@ class TApplication extends TComponent * Configuration file type, application.php and config.php */ const CONFIG_TYPE_PHP = 'php'; - /** * Runtime directory name */ @@ -588,16 +587,25 @@ class TApplication extends TComponent $this->_configFile=$value; } + /** + * @return string the application configuration file (absolute path) + */ public function getConfigurationType() { return $this->_configType; } + /** + * @param string the application configuration type. 'xml' and 'php' are valid values + */ public function setConfigurationType($value) { $this->_configType = $value; } + /** + * @return string the applictaion configuration type. default is 'xml' + */ public function getConfigurationFileExt() { if($this->_configFileExt===null) @@ -614,6 +622,9 @@ class TApplication extends TComponent return $this->_configFileExt; } + /** + * @return string the default configuration file name + */ public function getConfigurationFileName() { static $fileName; @@ -1242,6 +1253,7 @@ class TApplicationMode extends TEnumerable * This class is used internally by TApplication to parse and represent application configuration. * * @author Qiang Xue <qiang.xue@gmail.com> + * @author Carl G. Mathisen <carlgmathisen@gmail.com> * @version $Id$ * @package System * @since 3.0 @@ -1309,6 +1321,11 @@ class TApplicationConfiguration extends TComponent return $this->_empty; } + /** + * Parses the application configuration given in terms of a PHP array. + * @param array the PHP array + * @param string the context path (for specifying relative paths) + */ public function loadFromPhp($config, $configPath) { // application properties @@ -1377,6 +1394,11 @@ class TApplicationConfiguration extends TComponent } } + /** + * Loads the paths PHP array + * @param array the paths PHP array + * @param string the context path (for specifying relative paths) + */ protected function loadPathsPhp($pathsNode, $configPath) { if(isset($pathsNode['aliases']) && is_array($pathsNode['aliases'])) @@ -1451,6 +1473,11 @@ class TApplicationConfiguration extends TComponent } } + /** + * Loads the modules PHP array. + * @param array the modules PHP array + * @param string the context path (for specifying relative paths) + */ protected function loadModulesPhp($modulesNode, $configPath) { foreach($modulesNode as $id=>$module) @@ -1499,6 +1526,11 @@ class TApplicationConfiguration extends TComponent } } + /** + * Loads the services PHP array. + * @param array the services PHP array + * @param string the context path (for specifying relative paths) + */ protected function loadServicesPhp($servicesNode,$configPath) { foreach($servicesNode as $id => $service) @@ -1506,7 +1538,6 @@ class TApplicationConfiguration extends TComponent 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; @@ -1540,6 +1571,11 @@ class TApplicationConfiguration extends TComponent } } + /** + * Loads the parameters PHP array. + * @param array the parameters PHP array + * @param string the context path (for specifying relative paths) + */ protected function loadParametersPhp($parametersNode,$configPath) { foreach($parametersNode as $id => $parameter) @@ -1592,6 +1628,11 @@ class TApplicationConfiguration extends TComponent } } + /** + * Loads the external PHP array. + * @param array the application PHP array + * @param string the context path (for specifying relative paths) + */ protected function loadExternalPhp($includeNode,$configPath) { foreach($includeNode as $include) diff --git a/framework/Util/TLogRouter.php b/framework/Util/TLogRouter.php index aa772194..c693d24a 100644 --- a/framework/Util/TLogRouter.php +++ b/framework/Util/TLogRouter.php @@ -27,10 +27,15 @@ Prado::using('System.Data.TDbConnection'); * <route class="TFileLogRoute" Categories="System.Web.UI" Levels="Warning" />
* <route class="TEmailLogRoute" Categories="Application" Levels="Fatal" Emails="admin@pradosoft.com" />
* </code>
+ * PHP configuration style:
+ * <code>
+ *
+ * </code>
* You can specify multiple routes with different filtering conditions and different
* targets, even if the routes are of the same type.
*
* @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Carl G. Mathisen <carlgmathisen@gmail.com>
* @version $Id$
* @package System.Util
* @since 3.0
@@ -38,10 +43,6 @@ Prado::using('System.Data.TDbConnection'); class TLogRouter extends TModule
{
/**
- * File extension of external configuration file
- */
- const CONFIG_FILE_EXT='.xml';
- /**
* @var array list of routes available
*/
private $_routes=array();
@@ -53,7 +54,7 @@ class TLogRouter extends TModule /**
* Initializes this module.
* This method is required by the IModule interface.
- * @param TXmlElement configuration for this module, can be null
+ * @param mixed configuration for this module, can be null
* @throws TConfigurationException if {@link getConfigFile ConfigFile} is invalid.
*/
public function init($config)
@@ -62,9 +63,17 @@ class TLogRouter extends TModule {
if(is_file($this->_configFile))
{
- $dom=new TXmlDocument;
- $dom->loadFromFile($this->_configFile);
- $this->loadConfig($dom);
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ $phpConfig = include $this->_configFile;
+ $this->loadConfig($phpConfig);
+ }
+ else
+ {
+ $dom=new TXmlDocument;
+ $dom->loadFromFile($this->_configFile);
+ $this->loadConfig($dom);
+ }
}
else
throw new TConfigurationException('logrouter_configfile_invalid',$this->_configFile);
@@ -74,24 +83,46 @@ class TLogRouter extends TModule }
/**
- * Loads configuration from an XML element
- * @param TXmlElement configuration node
+ * Loads configuration from an XML element or PHP array
+ * @param mixed configuration node
* @throws TConfigurationException if log route class or type is not specified
*/
- private function loadConfig($xml)
+ private function loadConfig($config)
{
- foreach($xml->getElementsByTagName('route') as $routeConfig)
+ if(is_array($config))
{
- $properties=$routeConfig->getAttributes();
- if(($class=$properties->remove('class'))===null)
- throw new TConfigurationException('logrouter_routeclass_required');
- $route=Prado::createComponent($class);
- if(!($route instanceof TLogRoute))
- throw new TConfigurationException('logrouter_routetype_invalid');
- foreach($properties as $name=>$value)
- $route->setSubproperty($name,$value);
- $this->_routes[]=$route;
- $route->init($routeConfig);
+ if(isset($config['routes']) && is_array($config['routes']))
+ {
+ foreach($config['routes'] as $route)
+ {
+ $properties = isset($route['properties'])?$route['properties']:array();
+ if(!isset($route['class']))
+ throw new TConfigurationException('logrouter_routeclass_required');
+ $route=Prado::createComponent($route['class']);
+ if(!($route instanceof TLogRoute))
+ throw new TConfigurationException('logrouter_routetype_invalid');
+ foreach($properties as $name=>$value)
+ $route->setSubproperty($name,$value);
+ $this->_routes[]=$route;
+ $route->init($routeConfig);
+ }
+ }
+ }
+ else
+ {
+ foreach($config->getElementsByTagName('route') as $routeConfig)
+ {
+ $properties=$routeConfig->getAttributes();
+ if(($class=$properties->remove('class'))===null)
+ throw new TConfigurationException('logrouter_routeclass_required');
+ $route=Prado::createComponent($class);
+ if(!($route instanceof TLogRoute))
+ throw new TConfigurationException('logrouter_routetype_invalid');
+ foreach($properties as $name=>$value)
+ $route->setSubproperty($name,$value);
+ $this->_routes[]=$route;
+ $route->init($routeConfig);
+ }
}
}
@@ -124,7 +155,7 @@ class TLogRouter extends TModule */
public function setConfigFile($value)
{
- if(($this->_configFile=Prado::getPathOfNamespace($value,self::CONFIG_FILE_EXT))===null)
+ if(($this->_configFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null)
throw new TConfigurationException('logrouter_configfile_invalid',$value);
}
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 © 2005-2008 PradoSoft + * @copyright Copyright © 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);
}
}
diff --git a/framework/Web/Services/TFeedService.php b/framework/Web/Services/TFeedService.php index 7ecd10a7..d4afbade 100644 --- a/framework/Web/Services/TFeedService.php +++ b/framework/Web/Services/TFeedService.php @@ -5,7 +5,7 @@ * @author Qiang Xue <qiang.xue@gmail.com>
* @author Knut Urdalen <knut.urdalen@gmail.com>
* @link http://www.pradosoft.com
- * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Web.Services
@@ -28,6 +28,20 @@ * </service>
* </code>
* where each <feed> element specifies a feed identified by its "id" value (case-sensitive).
+ *
+ * PHP configuration style:
+ * <code>
+ * array(
+ * 'feed' => array(
+ * 'ch1' => array(
+ * 'class' => 'Path.To.FeedClass1',
+ * 'properties' => array(
+ * ...
+ * ),
+ * ),
+ * )
+ * </code>
+ *
* The class attribute indicates which PHP class will provide the actual feed
* content. Note, the class must implement {@link IFeedContentProvider} interface.
* Other initial properties for the feed class may also be specified in the
@@ -38,6 +52,7 @@ *
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Knut Urdalen <knut.urdalen@gmail.com>
+ * @author Carl G. Mathisen <carlgmathisen@gmail.com>
* @package System.Web.Services
* @since 3.1
*/
@@ -48,16 +63,27 @@ class TFeedService extends TService /**
* Initializes this module.
* This method is required by the IModule interface.
- * @param TXmlElement configuration for this module, can be null
+ * @param mixed configuration for this module, can be null
*/
public function init($config)
{
- foreach($config->getElementsByTagName('feed') as $feed)
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
{
- if(($id=$feed->getAttributes()->remove('id'))!==null)
- $this->_feeds[$id]=$feed;
- else
- throw new TConfigurationException('feedservice_id_required');
+ if(is_array($config))
+ {
+ foreach($config as $id => $feed)
+ $this->_feeds[$id] = $feed;
+ }
+ }
+ else
+ {
+ foreach($config->getElementsByTagName('feed') as $feed)
+ {
+ if(($id=$feed->getAttributes()->remove('id'))!==null)
+ $this->_feeds[$id]=$feed;
+ else
+ throw new TConfigurationException('feedservice_id_required');
+ }
}
}
@@ -79,27 +105,43 @@ class TFeedService extends TService if(isset($this->_feeds[$id]))
{
$feedConfig=$this->_feeds[$id];
- $properties=$feedConfig->getAttributes();
- if(($class=$properties->remove('class'))!==null)
+ $properties = array();
+ $feed = null;
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
{
- $feed=Prado::createComponent($class);
- if($feed instanceof IFeedContentProvider)
+ if(isset($feedConfig['class']))
{
- // init feed properties
- foreach($properties as $name=>$value)
- $feed->setSubproperty($name,$value);
- $feed->init($feedConfig);
-
- $content=$feed->getFeedContent();
- //$this->getResponse()->setContentType('application/rss+xml');
- $this->getResponse()->setContentType($feed->getContentType());
- $this->getResponse()->write($content);
+ $feed=Prado::createComponent($feedConfig['class']);
+ if($service instanceof IFeedContentProvider)
+ $properties=isset($feedConfig['properties'])?$feedConfig['properties']:array();
+ else
+ throw new TConfigurationException('jsonservice_response_type_invalid',$id);
}
else
- throw new TConfigurationException('feedservice_feedtype_invalid',$id);
+ throw new TConfigurationException('jsonservice_class_required',$id);
}
else
- throw new TConfigurationException('feedservice_class_required',$id);
+ {
+ $properties=$feedConfig->getAttributes();
+ if(($class=$properties->remove('class'))!==null)
+ {
+ $feed=Prado::createComponent($class);
+ if(!($feed instanceof IFeedContentProvider))
+ throw new TConfigurationException('feedservice_feedtype_invalid',$id);
+ }
+ else
+ throw new TConfigurationException('feedservice_class_required',$id);
+ }
+
+ // init feed properties
+ foreach($properties as $name=>$value)
+ $feed->setSubproperty($name,$value);
+ $feed->init($feedConfig);
+
+ $content=$feed->getFeedContent();
+ //$this->getResponse()->setContentType('application/rss+xml');
+ $this->getResponse()->setContentType($feed->getContentType());
+ $this->getResponse()->write($content);
}
else
throw new THttpException(404,'feedservice_feed_unknown',$id);
diff --git a/framework/Web/Services/TJsonService.php b/framework/Web/Services/TJsonService.php index e3ed9a7f..84f2dee2 100644 --- a/framework/Web/Services/TJsonService.php +++ b/framework/Web/Services/TJsonService.php @@ -29,10 +29,24 @@ * where each JSON response is specified via a <json> element.
* Initial property values can be configured in a <json> element.
*
+ *
+ * PHP configuration style:
+ * <code>
+ * 'services' => array(
+ * 'get_article' => array(
+ * 'class' => 'Path.To.JsonResponseClass1',
+ * 'properties' => array(
+ * ...
+ * )
+ * )
+ * )
+ * </code>
+ *
* To retrieve the JSON content provided by "get_article", use the URL
* <code>index.php?json=get_article</code>
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
+ * @author Carl G. Mathisen <carlgmathisen@gmail.com>
* @version $Id$
* @package System.Web.Services
* @since 3.1
@@ -47,7 +61,7 @@ class TJsonService extends TService /**
* Initializes this module.
* This method is required by the IModule interface.
- * @param TXmlElement configuration for this module, can be null
+ * @param mixed configuration for this module, can be null
*/
public function init($xml)
{
@@ -56,16 +70,27 @@ class TJsonService extends TService /**
* Load the service definitions.
- * @param TXmlElement configuration for this module, can be null
+ * @param mixed configuration for this module, can be null
*/
- protected function loadJsonServices($xml)
+ protected function loadJsonServices($config)
{
- foreach($xml->getElementsByTagName('json') as $config)
+ if($this->getApplication->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
{
- if(($id=$config->getAttribute('id'))!==null)
- $this->_services[$id]=$config;
- else
- throw new TConfigurationException('jsonservice_id_required');
+ if(is_array($config))
+ {
+ foreach($config as $id => $json)
+ $this->_services[$id] = $json;
+ }
+ }
+ else
+ {
+ foreach($config->getElementsByTagName('json') as $json)
+ {
+ if(($id=$json->getAttribute('id'))!==null)
+ $this->_services[$id]=$config;
+ else
+ throw new TConfigurationException('jsonservice_id_required');
+ }
}
}
@@ -79,20 +104,39 @@ class TJsonService extends TService if(isset($this->_services[$id]))
{
$serviceConfig=$this->_services[$id];
- $properties=$serviceConfig->getAttributes();
- if(($class=$properties->remove('class'))!==null)
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
{
- $service=Prado::createComponent($class);
- if($service instanceof TJsonResponse)
- $this->createJsonResponse($service,$properties,$serviceConfig);
+ if(isset($serviceConfig['class']))
+ {
+ $service=Prado::createComponent($serviceConfig['class']);
+ if($service instanceof JsonResponse)
+ {
+ $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:array();
+ $this->createJsonResponse($service,$properties,$serviceConfig);
+ }
+ else
+ throw new TConfigurationException('jsonservice_response_type_invalid',$id);
+ }
else
- throw new TConfigurationException('jsonservice_response_type_invalid',$id);
+ throw new TConfigurationException('jsonservice_class_required',$id);
}
else
- throw new TConfigurationException('jsonservice_class_required',$id);
+ {
+ $properties=$serviceConfig->getAttributes();
+ if(($class=$properties->remove('class'))!==null)
+ {
+ $service=Prado::createComponent($class);
+ if($service instanceof TJsonResponse)
+ $this->createJsonResponse($service,$properties,$serviceConfig);
+ else
+ throw new TConfigurationException('jsonservice_response_type_invalid',$id);
+ }
+ else
+ throw new TConfigurationException('jsonservice_class_required',$id);
+ }
}
else
- throw new THttpException(404,'jsonservice_provider_unknown',$id);
+ throw new THttpException(404,'jsonservice_feed_unknown',$id);
}
/**
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index 10c7da6e..4d08ed4c 100644 --- a/framework/Web/Services/TPageService.php +++ b/framework/Web/Services/TPageService.php @@ -69,6 +69,7 @@ Prado::using('System.Web.UI.TThemeManager'); * accessing to any resources.
*
* @author Qiang Xue <qiang.xue@gmail.com>
+ * @author Carl G. Mathisen <carlgmathisen@gmail.com>
* @version $Id$
* @package System.Web.Services
* @since 3.0
@@ -274,7 +275,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());
$cache->set(self::CONFIG_CACHE_PREFIX.$this->getID().$pagePath,array($pageConfig,$currentTimestamp));
}
@@ -721,6 +727,7 @@ class TPageConfiguration extends TComponent $rules[]=new TAuthorizationRule($action,$users,$roles,$verb,$ips);
}
}
+ $this->_rules=array_merge($rules,$this->_rules);
}
// pages
if(isset($config['pages']) && is_array($config['pages']))
@@ -747,7 +754,6 @@ class TPageConfiguration extends TComponent if($matching)
$this->_properties=array_merge($this->_properties,$properties);
}
- $this->_rules=array_merge($rules,$this->_rules);
}
// external configurations
diff --git a/framework/Web/Services/TSoapService.php b/framework/Web/Services/TSoapService.php index f5962647..d528fe1d 100644 --- a/framework/Web/Services/TSoapService.php +++ b/framework/Web/Services/TSoapService.php @@ -30,12 +30,16 @@ * </service> * </services> * </code> - * - * The above example specifies a single SOAP provider named "stockquote" - * whose class is "MyStockQuote". A SOAP client can then obtain the WSDL for - * this provider via the following URL: + * PHP configuration style: * <code> - * http://hostname/path/to/index.php?soap=stockquote.wsdl + * 'services' => array( + * 'soap' => array( + * 'class' => 'System.Web.Services.TSoapService' + * 'properties' => array( + * 'provider' => 'MyStockQuote' + * ) + * ) + * ) * </code> * * The WSDL for the provider class "MyStockQuote" is generated based on special @@ -79,13 +83,13 @@ * * @author Knut Urdalen <knut.urdalen@gmail.com> * @author Qiang Xue <qiang.xue@gmail.com> + * @author Carl G. Mathisen <carlgmathisen@gmail.com> * @package System.Web.Services * @since 3.1 */ class TSoapService extends TService { const DEFAULT_SOAP_SERVER='TSoapServer'; - const CONFIG_FILE_EXT='.xml'; private $_servers=array(); private $_configFile=null; private $_wsdlRequest=false; @@ -195,7 +199,7 @@ class TSoapService extends TService */ public function setConfigFile($value) { - if(($this->_configFile=Prado::getPathOfNamespace($value,self::CONFIG_FILE_EXT))===null) + if(($this->_configFile=Prado::getPathOfNamespace($value,Prado::getApplication()->getConfigurationFileExt()))===null) throw new TConfigurationException('soapservice_configfile_invalid',$value); } @@ -237,7 +241,12 @@ class TSoapService extends TService protected function createServer() { $properties=$this->_servers[$this->_serverID]; - if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP || ($serverClass=$properties->remove('class'))===null) + $serverClass=null; + if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP && isset($config['class'])) + $serverClass=$config['class']; + else if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_XML) + $serverClass=$properties->remove('class'); + if($serverClass===null) $serverClass=self::DEFAULT_SOAP_SERVER; Prado::using($serverClass); $className=($pos=strrpos($serverClass,'.'))!==false?substr($serverClass,$pos+1):$serverClass; diff --git a/framework/Web/TUrlMapping.php b/framework/Web/TUrlMapping.php index 83dd99b6..30e62496 100644 --- a/framework/Web/TUrlMapping.php +++ b/framework/Web/TUrlMapping.php @@ -4,7 +4,7 @@ *
* @author Wei Zhuo <weizhuo[at]gamil[dot]com>
* @link http://www.pradosoft.com/
- * @copyright Copyright © 2005-2008 PradoSoft + * @copyright Copyright © 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Web
@@ -70,10 +70,6 @@ Prado::using('System.Collections.TAttributeCollection'); class TUrlMapping extends TUrlManager
{
/**
- * File extension of external configuration file
- */
- const CONFIG_FILE_EXT='.xml';
- /**
* @var TUrlMappingPattern[] list of patterns.
*/
protected $_patterns=array();
@@ -101,17 +97,17 @@ class TUrlMapping extends TUrlManager /**
* Initializes this module.
* This method is required by the IModule interface.
- * @param TXmlElement configuration for this module, can be null
+ * @param mixed configuration for this module, can be null
* @throws TConfigurationException if module is configured in the global scope.
*/
- public function init($xml)
+ public function init($config)
{
- parent::init($xml);
+ parent::init($config);
if($this->getRequest()->getRequestResolved())
throw new TConfigurationException('urlmapping_global_required');
if($this->_configFile!==null)
$this->loadConfigFile();
- $this->loadUrlMappings($xml);
+ $this->loadUrlMappings($config);
if($this->_urlPrefix==='')
$this->_urlPrefix=$this->getRequest()->getApplicationUrl();
$this->_urlPrefix=rtrim($this->_urlPrefix,'/');
@@ -125,9 +121,17 @@ class TUrlMapping extends TUrlManager {
if(is_file($this->_configFile))
{
- $dom=new TXmlDocument;
- $dom->loadFromFile($this->_configFile);
- $this->loadUrlMappings($dom);
+ if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP)
+ {
+ $config = include $this->_configFile;
+ $this->loadUrlMappings($dom);
+ }
+ else
+ {
+ $dom=new TXmlDocument;
+ $dom->loadFromFile($this->_configFile);
+ $this->loadUrlMappings($dom);
+ }
}
else
throw new TConfigurationException('urlmapping_configfile_inexistent',$this->_configFile);
@@ -191,7 +195,7 @@ class TUrlMapping extends TUrlManager */
public function setConfigFile($value)
{
- if(($this->_configFile=Prado::getPathOfNamespace($value,self::CONFIG_FILE_EXT))===null)
+ if(($this->_configFile=Prado::getPathOfNamespace($value,$this->getApplication()->getConfigurationFileExt()))===null)
throw new TConfigurationException('urlmapping_configfile_invalid',$value);
}
@@ -218,28 +222,52 @@ class TUrlMapping extends TUrlManager /**
* Load and configure each url mapping pattern.
- * @param TXmlElement configuration node
+ * @param mixed configuration node
* @throws TConfigurationException if specific pattern class is invalid
*/
- protected function loadUrlMappings($xml)
+ protected function loadUrlMappings($config)
{
- foreach($xml->getElementsByTagName('url') as $url)
+ if(is_array($config))
{
- $properties=$url->getAttributes();
- if(($class=$properties->remove('class'))===null)
- $class=$this->getDefaultMappingClass();
- $pattern=Prado::createComponent($class,$this);
- if(!($pattern instanceof TUrlMappingPattern))
- throw new TConfigurationException('urlmapping_urlmappingpattern_required');
- foreach($properties as $name=>$value)
- $pattern->setSubproperty($name,$value);
- $this->_patterns[]=$pattern;
- $pattern->init($url);
-
- $key=$pattern->getServiceID().':'.$pattern->getServiceParameter();
- $this->_constructRules[$key][]=$pattern;
+ if(isset($config['urls']) && is_array($config['urls']))
+ {
+ foreach($config['urls'] as $url)
+ {
+ $class=null;
+ if(!isset($url['class']))
+ $class=$this->getDefaultMappingClass();
+ $pattern=Prado::createComponent($class,$this);
+ $properties = isset($url['properties'])?$url['properties']:array();
+ $this->buildUrlMapping($class,$pattern,$properties,$url);
+ }
+ }
+ }
+ else
+ {
+ foreach($config->getElementsByTagName('url') as $url)
+ {
+ $properties=$url->getAttributes();
+ if(($class=$properties->remove('class'))===null)
+ $class=$this->getDefaultMappingClass();
+ $pattern=Prado::createComponent($class,$this);
+ $this->buildUrlMapping($class,$pattern,$properties,$url);
+ }
}
}
+
+ private function buildUrlMapping($class, $pattern, $properties, $url)
+ {
+ $pattern=Prado::createComponent($class,$this);
+ if(!($pattern instanceof TUrlMappingPattern))
+ throw new TConfigurationException('urlmapping_urlmappingpattern_required');
+ foreach($properties as $name=>$value)
+ $pattern->setSubproperty($name,$value);
+ $this->_patterns[]=$pattern;
+ $pattern->init($url);
+
+ $key=$pattern->getServiceID().':'.$pattern->getServiceParameter();
+ $this->_constructRules[$key][]=$pattern;
+ }
/**
* Parses the request URL and returns an array of input parameters.
@@ -264,7 +292,7 @@ class TUrlMapping extends TUrlManager if(is_string($key))
$params[$key]=$value;
}
- if (!$pattern->getIsWildCardPattern()) + if (!$pattern->getIsWildCardPattern())
$params[$pattern->getServiceID()]=$pattern->getServiceParameter();
return $params;
}
@@ -300,8 +328,8 @@ class TUrlMapping extends TUrlManager if(!(is_array($getItems) || ($getItems instanceof Traversable)))
$getItems=array();
$key=$serviceID.':'.$serviceParam;
- $wildCardKey = ($pos=strrpos($serviceParam,'.'))!==false ? - $serviceID.':'.substr($serviceParam,0,$pos).'.*' : $serviceID.':*'; + $wildCardKey = ($pos=strrpos($serviceParam,'.'))!==false ?
+ $serviceID.':'.substr($serviceParam,0,$pos).'.*' : $serviceID.':*';
if(isset($this->_constructRules[$key]))
{
foreach($this->_constructRules[$key] as $rule)
@@ -309,16 +337,16 @@ class TUrlMapping extends TUrlManager if($rule->supportCustomUrl($getItems))
return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems);
}
- } - elseif(isset($this->_constructRules[$wildCardKey])) - { + }
+ elseif(isset($this->_constructRules[$wildCardKey]))
+ {
foreach($this->_constructRules[$wildCardKey] as $rule)
{
if($rule->supportCustomUrl($getItems))
- { - $getItems['*']= $pos ? substr($serviceParam,$pos+1) : $serviceParam; + {
+ $getItems['*']= $pos ? substr($serviceParam,$pos+1) : $serviceParam;
return $rule->constructUrl($getItems,$encodeAmpersand,$encodeGetItems);
- } + }
}
}
}
@@ -413,8 +441,8 @@ class TUrlMappingPattern extends TComponent private $_manager;
private $_caseSensitive=true;
- - private $_isWildCardPattern=false; +
+ private $_isWildCardPattern=false;
/**
* Constructor.
@@ -444,8 +472,8 @@ class TUrlMappingPattern extends TComponent {
if($this->_serviceParameter===null)
throw new TConfigurationException('urlmappingpattern_serviceparameter_required', $this->getPattern());
- if(strpos($this->_serviceParameter,'*')!==false) - $this->_isWildCardPattern=true; + if(strpos($this->_serviceParameter,'*')!==false)
+ $this->_isWildCardPattern=true;
}
/**
@@ -462,11 +490,11 @@ class TUrlMappingPattern extends TComponent $params[]='{'.$key.'}';
$values[]='(?P<'.$key.'>'.$value.')';
}
- if ($this->getIsWildCardPattern()) { - $params[]='{*}'; - // service parameter must not contain '=' and '/' - $values[]='(?P<'.$this->getServiceID().'>[^=/]+)'; - } + if ($this->getIsWildCardPattern()) {
+ $params[]='{*}';
+ // service parameter must not contain '=' and '/'
+ $values[]='(?P<'.$this->getServiceID().'>[^=/]+)';
+ }
$params[]='/';
$values[]='\\/';
$regexp=str_replace($params,$values,trim($this->getPattern(),'/').'/');
@@ -608,13 +636,13 @@ class TUrlMappingPattern extends TComponent }
/**
- * @return boolean whether this pattern is a wildcard pattern + * @return boolean whether this pattern is a wildcard pattern
* @since 3.1.4
*/
- public function getIsWildCardPattern() { - return $this->_isWildCardPattern; - } - + public function getIsWildCardPattern() {
+ return $this->_isWildCardPattern;
+ }
+
/**
* @param array list of GET items to be put in the constructed URL
* @return boolean whether this pattern IS the one for constructing the URL with the specified GET items.
|