summaryrefslogtreecommitdiff
path: root/framework/Web/Services/TFeedService.php
diff options
context:
space:
mode:
authorcarlgmathisen <>2008-12-07 13:05:05 +0000
committercarlgmathisen <>2008-12-07 13:05:05 +0000
commit736e92efbc75908a2bf26fe333a03990e3bb8100 (patch)
tree21dfe413b2f3f52704ca28e17f22269f9cfdb5ea /framework/Web/Services/TFeedService.php
parent6228873cf9d6471463d2413e7dfd7447f759baf2 (diff)
work on php style configuration
Diffstat (limited to 'framework/Web/Services/TFeedService.php')
-rw-r--r--framework/Web/Services/TFeedService.php86
1 files changed, 64 insertions, 22 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 &copy; 2005-2008 PradoSoft
+ * @copyright Copyright &copy; 2005-2008 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id$
* @package System.Web.Services
@@ -28,6 +28,20 @@
* </service>
* </code>
* where each &lt;feed&gt; 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);