Missing from it:
a) printf() type messages for arguments: (needed to enable translatable messages)
Possible solution:?
throw new PEAR_Exception("mymessage", MY_ID)
throw new PEAR_Exception(array("my message %s",$somearg), MY_ID)
Umm, this would need to accept that params and accept something a callback for actually doing the translation no? Why not pass directly the translated string?
I guess since translation is not something you really want to mess around with when writing and maintaining the class/packages. The idea of being able to add a translation hook in the error handler would allow those who wanted to use translated messages, a simple mechanism to do it.
eg.
PEAR_Exception::translator(array(&$translator,'get'));
PEAR_Exception::translator('gettext');
or better, just make the translator a special observer.. (although it does more than observe!) - keeps the API kiss.. and thin.
PEAR_Exception::addObserver('translator','gettext');
PEAR_Exception::addObserver('translator',array(&$translator,'get'));
- A static method for pushing errors in the internal stack
- A static method for getting the array of warnings
- Ability to attach observers to warnings too.
PEAR_Exception::addObserver('warning',PEAR_OBSERVER_TRIGGER);
$foo = new foo;
$foo->bar();
$warnings = PEAR_Exception::getWarnings($class = null);
$warning = PEAR_Exception::lastWarning();
or just
$warning = PEAR_Exception::last();
maybe only store the last warning/exception?.. - if you want to know more, then adding PEAR_Exception_Stack as an observer to PEAR_Exception would be more effecient - that way we avoid storing a huge array of historical data unnecessarily.
Regards
Alan
--
Can you help out?
Need Consulting Services or Know of a Job?
http://www.akbkhome.com