FeedFormat.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 /* $Id: FeedFormat.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     abstract class FeedFormat extends Singleton
00017     {
00018         abstract public function getChannelWorker();
00019         abstract public function getItemWorker();
00020         abstract public function isAcceptable(SimpleXMLElement $xmlFeed);
00021         
00022         public function parse(SimpleXMLElement $xmlFeed)
00023         {
00024             $this->checkWorkers();
00025             
00026             return
00027                 $this->getChannelWorker()->
00028                     makeChannel($xmlFeed)->
00029                         setFeedItems(
00030                             $this->getItemWorker()->
00031                                 makeItems($xmlFeed)
00032                         );
00033         }
00034         
00035         public function toXml(FeedChannel $channel)
00036         {
00037             $this->checkWorkers();
00038             
00039             $itemsXml = null;
00040             $itemWorker = $this->getItemWorker();
00041             
00042             foreach ($channel->getFeedItems() as $feedItem)
00043                 $itemsXml .= $itemWorker->toXml($feedItem);
00044             
00045             return $this->getChannelWorker()->toXml($channel, $itemsXml);
00046         }
00047         
00048         private function checkWorkers()
00049         {
00050             if (!$this->getChannelWorker())
00051                 throw new WrongStateException(
00052                     'Setup channelWorker must be assigned'
00053                 );
00054             
00055             if (!$this->getItemWorker())
00056                 throw new WrongStateException(
00057                     'Setup itemWorker must be assigned'
00058                 );
00059             
00060             return $this;
00061         }
00062     }
00063 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4