diff options
author | Christophe.Boulain <> | 2009-05-27 13:55:58 +0000 |
---|---|---|
committer | Christophe.Boulain <> | 2009-05-27 13:55:58 +0000 |
commit | 7d15c048340cbcbd06cb9664b479d45906d2b0d8 (patch) | |
tree | 0af02875479def0e52d5ea1b6d11b5a276a477a6 /framework/Web | |
parent | 5a87ceb5ce3a62aae92c344f670059971d5914d9 (diff) | |
parent | 9a87732ce51fd34e312ac63ed1ebec8d7fc1c16f (diff) |
Merge from 3.2 branch.
Beginning of Prado 3.2 development
Diffstat (limited to 'framework/Web')
-rw-r--r-- | framework/Web/Services/TFeedService.php | 86 | ||||
-rw-r--r-- | framework/Web/Services/TJsonService.php | 74 | ||||
-rw-r--r-- | framework/Web/Services/TPageService.php | 158 | ||||
-rw-r--r-- | framework/Web/Services/TSoapService.php | 61 | ||||
-rw-r--r-- | framework/Web/TUrlMapping.php | 194 |
5 files changed, 424 insertions, 149 deletions
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..52997358 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['json'] 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,17 +104,36 @@ 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 TJsonResponse)
+ {
+ $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);
diff --git a/framework/Web/Services/TPageService.php b/framework/Web/Services/TPageService.php index e35fb0e3..e4f9804c 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
@@ -78,7 +79,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 +183,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 +218,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 +259,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;
}
@@ -262,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));
}
@@ -581,16 +599,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 +625,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 +660,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 +680,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);
+ }
+ }
+ $this->_rules=array_merge($rules,$this->_rules);
+ }
+ // 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);
+ }
+ }
+
+ // 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
diff --git a/framework/Web/Services/TSoapService.php b/framework/Web/Services/TSoapService.php index d943d6fb..ddb5cecb 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; @@ -148,19 +152,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) { - $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; + if(is_array($config)) + { + foreach($config['soap'] 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 + { + 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; + } } } @@ -179,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); } @@ -221,7 +241,12 @@ class TSoapService extends TService protected function createServer() { $properties=$this->_servers[$this->_serverID]; - if(($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 47232401..09e45d99 100644 --- a/framework/Web/TUrlMapping.php +++ b/framework/Web/TUrlMapping.php @@ -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))
+ {
+ 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
{
- $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;
+ 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;
}
@@ -450,11 +478,11 @@ class TUrlMappingPattern extends TComponent private $_caseSensitive=true;
- private $_isWildCardPattern=false; - - private $_urlFormat=THttpRequestUrlFormat::Get; - - private $_separator='/'; + private $_isWildCardPattern=false;
+
+ private $_urlFormat=THttpRequestUrlFormat::Get;
+
+ private $_separator='/';
/**
* Constructor.
@@ -676,57 +704,57 @@ 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; - } - - /** - * @return THttpRequestUrlFormat the format of URLs. Defaults to THttpRequestUrlFormat::Get. - */ - public function getUrlFormat() - { - return $this->_urlFormat; - } - - /** - * Sets the format of URLs constructed and interpreted by this pattern. - * A Get URL format is like index.php?name1=value1&name2=value2 - * while a Path URL format is like index.php/name1/value1/name2/value. - * The separating character between name and value can be configured with - * {@link setUrlParamSeparator} and defaults to '/'. - * Changing the UrlFormat will affect {@link constructUrl} and how GET variables - * are parsed. - * @param THttpRequestUrlFormat the format of URLs. - * @param since 3.1.4 - */ - public function setUrlFormat($value) - { - $this->_urlFormat=TPropertyValue::ensureEnum($value,'THttpRequestUrlFormat'); - } - - /** - * @return string separator used to separate GET variable name and value when URL format is Path. Defaults to slash '/'. - */ - public function getUrlParamSeparator() - { - return $this->_separator; - } - - /** - * @param string separator used to separate GET variable name and value when URL format is Path. - * @throws TInvalidDataValueException if the separator is not a single character - */ - public function setUrlParamSeparator($value) - { - if(strlen($value)===1) - $this->_separator=$value; - else - throw new TInvalidDataValueException('httprequest_separator_invalid'); - } - + public function getIsWildCardPattern() {
+ return $this->_isWildCardPattern;
+ }
+
+ /**
+ * @return THttpRequestUrlFormat the format of URLs. Defaults to THttpRequestUrlFormat::Get.
+ */
+ public function getUrlFormat()
+ {
+ return $this->_urlFormat;
+ }
+
+ /**
+ * Sets the format of URLs constructed and interpreted by this pattern.
+ * A Get URL format is like index.php?name1=value1&name2=value2
+ * while a Path URL format is like index.php/name1/value1/name2/value.
+ * The separating character between name and value can be configured with
+ * {@link setUrlParamSeparator} and defaults to '/'.
+ * Changing the UrlFormat will affect {@link constructUrl} and how GET variables
+ * are parsed.
+ * @param THttpRequestUrlFormat the format of URLs.
+ * @param since 3.1.4
+ */
+ public function setUrlFormat($value)
+ {
+ $this->_urlFormat=TPropertyValue::ensureEnum($value,'THttpRequestUrlFormat');
+ }
+
+ /**
+ * @return string separator used to separate GET variable name and value when URL format is Path. Defaults to slash '/'.
+ */
+ public function getUrlParamSeparator()
+ {
+ return $this->_separator;
+ }
+
+ /**
+ * @param string separator used to separate GET variable name and value when URL format is Path.
+ * @throws TInvalidDataValueException if the separator is not a single character
+ */
+ public function setUrlParamSeparator($value)
+ {
+ if(strlen($value)===1)
+ $this->_separator=$value;
+ else
+ throw new TInvalidDataValueException('httprequest_separator_invalid');
+ }
+
/**
* @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.
|