Open ghost opened 12 years ago
A IMHO simpler approach would be to use a derived class for each type of feed:
class RSS2FeedWriter extends FeedWriter
{
function __construct()
{
parent::__construct(RSS2);
}
}
Important would be to change the visibility of the constructor of the FeedWriter class to protected
. This would enforce the use of the three sub-classes from outside.
I've just tested this, and it works flawlessly. The only change is to create an RSS2FeedWriter
instead of an FeedWriter
instance when using the code.
Hey up, yeah I'd go with that, but u might want to consider extracting the responsibilities out of the super class ;) though that would be quite a big job & I don't think it'd be worth anyone's time doing that refactoring yet. Maybe if more feed formats start to take over RSS and atom, maybe then ;)
Oh might also want to set the super class to abstract - since u can't instantiate the class without extending it :) though setting the class to abstract and the constructor to protected would break backward compatibility.... Meaning maybe hold that back until the next major release?
Yes, I have the same opinion: The base class should be independent from any feed type and offering just functions for the core XML stuff. Are there some new feed types on the horizon?
Since this is a relatively small project I never thought about "real" releases - HEAD should always work...
Might be worth while just creating a quick branch for version 2 that includes the proper refactoring - if you got the time that is. At the end of the day the code that's there now works perfectly fine so it's really not a big problem :)
Regarding the feed types... thinking more of custom feeds or internal syndication feeds such as a private feed format specialised for providing transcripts for podcasts where the internal readers can understand them but public ones wouldn't. Since you have called it the "Universal" feed writer ;)
P.S. Whens the Universal Feed Reader coming? Complete set then!
Just expanding on the previous patch. A better idea would be to remove the responsibility of the writer class having to valid the format is valid. So in the class below i have removed that responsibility to a new format class, which can then make use of type hinting to enforce the correct type is given to the constructor of the writer class.
Not tested this code and it's almost 1am for me, but it's just to show you a rough idea of how it would work and how it would make adding new formats a little easier in the future. Hope it helps or at least gives you more ideas.
Just a thought.
Kind regards, Scott