RssChannelWorker.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2007 by Dmitry A. Lomash, Dmitry E. Demidov             *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00015     final class RssChannelWorker extends Singleton implements FeedChannelWorker
00016     {
00020         public static function me()
00021         {
00022             return Singleton::getInstance(__CLASS__);
00023         }
00024         
00028         public function makeChannel(SimpleXMLElement $xmlFeed)
00029         {
00030             if (
00031                 (!isset($xmlFeed->channel))
00032                 || (!isset($xmlFeed->channel->title))
00033             )
00034                 throw new WrongStateException(
00035                     'there are no channels in given rss'
00036                 );
00037             
00038             $feedChannel =
00039                 FeedChannel::create((string) $xmlFeed->channel->title);
00040             
00041             if (isset($xmlFeed->channel->link))
00042                 $feedChannel->setLink((string) $xmlFeed->channel->link);
00043             
00044             return $feedChannel;
00045         }
00046         
00047         public function toXml(FeedChannel $channel, $itemsXml)
00048         {
00049             return
00050                 '<rss version="'.RssFeedFormat::VERSION.'">'
00051                     .'<channel>'
00052                         .'<title>'.$channel->getTitle().'</title>'
00053                         .(
00054                             $channel->getLink()
00055                                 ? '<link>'.$channel->getLink().'</link>'
00056                                 : null
00057                         )
00058                         .(
00059                             $channel->getDescription()
00060                                 ?
00061                                     '<description>'
00062                                     .$channel->getDescription()
00063                                     .'</description>'
00064                                 : null
00065                         )
00066                         .$itemsXml
00067                     .'</channel>'
00068                 .'</rss>';
00069         }
00070     }
00071 ?>