Re: Design for PHP Weather 2
Brought to you by:
iridium
|
From: Martin G. <gim...@gi...> - 2002-03-16 00:17:54
|
"Martin Geisler" <gim...@gi...> writes:
> Hi again
I'll just expand on what I said a little earlier...
> 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.
So, instead of having this:
---> output_(text/icons/...)
/
DB <----> phpweather <--<
\
---> locale_(en/da/...)
where the locale has to work together with the output-modules in a
rather tricky way, I think we should have this:
+-- output_text_en
|
---> output_text <--+-- output_text_da
/ |
DB <---- phpweather <---+---> output_icons +-- output_text_xx
\
---> output_wap <---+-- output_wap_en
|
+-- output_wap_da
|
+-- output_wap_xx
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.
> So you would probably do something like this:
>
> $weather =3D new phpweather('EKYT');
> $locale =3D new pw_locale_en();
> $text =3D new pw_module_text($weather, $locale,
> array('mark_begin' =3D> '<i>',
> 'mark_end' =3D> '</i>');
> $icon =3D new pw_module_icon($weather);
>
> echo $text->get_output();
> echo '<img src=3D"' . $icon->get_output() . '">';
With the new proposal, this would be something like this:
$weather =3D new phpweather('EKYT');
$text =3D new pw_output_text_en($weather,
array('mark_begin' =3D> '<i>',
'mark_end' =3D> '</i>'));
$icon =3D new pw_output_icon($weather);
echo $text->get_output();
echo '<img src=3D"' . $icon->get_output() . '">';
Or perhaps it should just be
$icon =3D new pw_output_icon($weather->get_data());
where get_data() would return an array with the parsed metar plus
things like the location etc.
> We would of course have to think about how we are going to let the
> locales customize the output of the modules...
That should work automatically now.
=2D-
Martin Geisler My GnuPG Key: 0xF7F6B57B
See my homepage at http://www.gimpster.com/ for:
PHP Weather =3D> Shows the current weather on your webpage.
PHP Shell =3D> A telnet-connection (almost :-) in a PHP page.
|