From 8c1edb7f4eced999c9704ec9ff7ba11d88248bbd Mon Sep 17 00:00:00 2001 From: xue <> Date: Mon, 22 May 2006 00:19:44 +0000 Subject: Added TFeedService. --- framework/Web/Services/TFeedService.php | 156 ++++++++++++++++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 framework/Web/Services/TFeedService.php (limited to 'framework/Web/Services/TFeedService.php') diff --git a/framework/Web/Services/TFeedService.php b/framework/Web/Services/TFeedService.php new file mode 100644 index 00000000..96f6cef4 --- /dev/null +++ b/framework/Web/Services/TFeedService.php @@ -0,0 +1,156 @@ + + * @author Knut Urdalen + * @link http://www.pradosoft.com + * @copyright Copyright © 2006 PradoSoft + * @license http://www.pradosoft.com/license/ + * @package System.Web.Services + */ + +/** + * TFeedService class + * + * TFeedService provides to end-users feed content. + * + * TFeedService manages a set of {@link TFeed}, each representing specific feed content. + * The service parameter, referring to the ID of the feed, specifies + * which feed content to be provided to end-users. + * + * To use TFeedService, configure it in application configuration as follows, + * + * + * + * + * + * + * + * where each feed is specified via a <feed> element. Initial property + * values can be configured in a <feed> element. + * + * To retrieve the feed content provided by "ch2", use the URL + * index.php?feed=ch2 + * + * @author Qiang Xue + * @author Knut Urdalen + * @package System.Web.Services + * @since 3.1 + */ +class TFeedService extends TService +{ + private $_feeds=array(); + + /** + * Initializes this module. + * This method is required by the IModule interface. + * @param TXmlElement configuration for this module, can be null + */ + public function init($config) + { + foreach($config->getElementsByTagName('feed') as $feed) + { + if(($id=$feed->getAttribute('id'))!==null) + $this->_feeds[$id]=$feed; + else + throw new TConfigurationException('feedservice_id_required'); + } + } + + /** + * @return string the requested feed path + */ + protected function determineRequestedFeedPath() + { + return $this->getRequest()->getServiceParameter(); + } + + /** + * Runs the service. + * This method is invoked by application automatically. + */ + public function run() + { + $id=$this->getRequest()->getServiceParameter(); + if(isset($this->_feeds[$id])) + { + $feedConfig=$this->_feeds[$id]; + $properties=$feedConfig->getAttributes(); + if(($class=$properties->remove('class'))!==null) + { + $feed=Prado::createComponent($class); + if($feed instanceof TFeed) + { + // 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('text/xml'); + $this->getResponse()->write($content); + } + else + throw new TConfigurationException('feedservice_feedtype_invalid',$id); + } + else + throw new TConfigurationException('feedservice_class_required',$id); + } + else + throw new THttpException(404,'feedservice_feed_unknown',$id); + } +} + +/** + * TFeed class. + * + * TFeed is the base class for all feed provider classes. + * + * Derived classes should override {@link getFeedContent()} to return + * an XML string that represents the feed content. + * + * @author Qiang Xue + * @version $Revision: $ $Date: $ + * @package System.Services + * @since 3.1 + */ +abstract class TFeed extends TApplicationComponent +{ + private $_id=''; + + /** + * Initializes the feed. + * @param TXmlElement configurations specified in {@link TFeedService}. + */ + public function init($config) + { + } + + /** + * @return string ID of this feed + */ + public function getID() + { + return $this->_id; + } + + /** + * @param string ID of this feed + */ + public function setID($value) + { + $this->_id=$value; + } + + /** + * @return string an XML string representing the feed content + */ + public function getFeedContent() + { + return ''; + } +} + +?> \ No newline at end of file -- cgit v1.2.3