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/TFeedService.php | 86 ++++++++++++++++++++++++--------- 1 file changed, 64 insertions(+), 22 deletions(-) (limited to 'framework/Web/Services/TFeedService.php') 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 * @author Knut Urdalen * @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 @@ * * * where each <feed> element specifies a feed identified by its "id" value (case-sensitive). + * + * PHP configuration style: + * + * array( + * 'feed' => array( + * 'ch1' => array( + * 'class' => 'Path.To.FeedClass1', + * 'properties' => array( + * ... + * ), + * ), + * ) + * + * * 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 * @author Knut Urdalen + * @author Carl G. Mathisen * @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); -- cgit v1.2.3