From 736e92efbc75908a2bf26fe333a03990e3bb8100 Mon Sep 17 00:00:00 2001
From: carlgmathisen <>
Date: Sun, 7 Dec 2008 13:05:05 +0000
Subject: work on php style configuration
---
framework/Web/Services/TJsonService.php | 76 ++++++++++++++++++++++++++-------
1 file changed, 60 insertions(+), 16 deletions(-)
(limited to 'framework/Web/Services/TJsonService.php')
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:
+ *
+ * 'services' => array(
+ * 'get_article' => array(
+ * 'class' => 'Path.To.JsonResponseClass1',
+ * 'properties' => array(
+ * ...
+ * )
+ * )
+ * )
+ *
+ *
* To retrieve the JSON content provided by "get_article", use the URL
* index.php?json=get_article
*
* @author Wei Zhuo
+ * @author Carl G. Mathisen
* @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);
}
/**
--
cgit v1.2.3