Re: Design for PHP Weather 2
Brought to you by:
iridium
From: Max H. <ma...@fl...> - 2002-03-16 01:03:27
|
> > My plan is to separate the METAR-parsing logic from the output. So > > we should have a class phpweather that handles the parsing of the > > METAR and uses the database-layer to cache it. > > > > Then we should have several modules (two so far) which talk to the > > phpweather object and retrieves the parsed METAR from it. They can > > also obtain things like the ICAO and location from the class > > phpweather (which can find this information in the database). > > > > The module should work together with a locale to produce the output. > > If it doesn't need any localization information, then the locale can > > be left out. > > I think it's going to be hard (impossible?) to separate the > output-modules from the locales. As it is now, locale_common should > probably be considered an output-module: it knows how to produce > textual output. The locales then extend this class. This cannot work > if there are more than one of these classes, so I suggest that we > simply drop the idea about having a seperate locale and output-module. I think that the locale is intrinsic in any function that returns text... > In this setup, phpweather is the superclass of metar-parser and the > db-layer. Seperated from hierarchy, we have the output-modules. We > have the three base-classes: output_text, output_icons, and > output_wap. The output_text and output_wap classes are sub-classed by > the different language-classes, whereas output_icons doesn't need any > internationalization. > > With the new proposal, this would be something like this: > > $weather = new phpweather('EKYT'); > $text = new pw_output_text_en($weather, > array('mark_begin' => '<i>', > 'mark_end' => '</i>')); > > $icon = new pw_output_icon($weather); > > echo $text->get_output(); > echo '<img src="' . $icon->get_output() . '">'; I'd be happier to see $weather = new pw_weather('EGBE'); $text = new pw_text($weather,"en"); $icons = new pw_icons($weather); echo $text->print_pretty() . '<br /> <img src="'.$icons->src_main().'" />'; etc. - let's not mess about with different functions for each locale, it'll be much easier to add new locales if we select it in the function itself, rather than defining the function to be locale-specific. An alternative to this schema is if the output functions actually extend the phpweather class, but I can see problems if we want to produce both text and icons... > Or perhaps it should just be > > $icon = new pw_output_icon($weather->get_data()); no. Let's do it properly OO. Pass it the object, then it'll be easier to get out anything we need at a later date. We should be consistent, so that any output function should take the $phpweather object. Max -- Never put the words "Diabolical Master Plan" on a CV |