While trying to find a source-code sherpa, I’ve been working on an LLSD parser- it’s mostly complete now, so I started work on an interface to LL’s capabilities services- here’s some snippets that show off the geekiness of the code:
4fbacb2fa357d1_
Here’s the kicker- uhu_capability_regapi::get_error_codes() doesn’t exist- overloading magic is at work. The actual uhu_capability_regapi class consists of the following chunk of code:
4fbacb2fa357d2_
When uhu_capability_regapi is instantiated, an authenticated call (using the uhu_SL_capability_user object) is made to uhu_capability_regapi::url() (not quite there yet with late static binding yet, still using call_user_func_array(get_class($this)) magic). This document is then parsed using a custom LLSD DTD (no point using the full LLSD spec when we know what to expect, is there ?), and stored as a named array.
When $regapi->get_error_codes() is called, uhu_capability_regapi::__call(‘get_error_codes’) is invoked- because this matches a value stored from the initial LLSD call, the class then fetches, parses and returns a usable structure of the returned LLSD document.
Now since I know what the calls returned by /get_reg_capabilities will be, you might be wondering why I’m using __call() magic. I present a hypothetical:
- I release the code, you download and use it.
- Linden Lab add another call on the regapi service, while I’m away on holiday/having power outtage.
If I didn’t use the __call() magic, you’d not be able to make use of the newly added feature unless you either patched it in yourself (which you may not have the time/skill/inclination to do), or waited till I got back, became aware of the new call, read through the documentation, added a new method, tested, updated documentation then released it.
By using the overloading features of PHP5, I’m able to “future proof” against any new calls added to a capability service without making any alterations to code. I don’t need to explicitly do anything to use the RegAPI now (once my account gets cleared for use with it, I’ll be able to test that theory :-P ), though I do plan to write a bunch of code to auto-populate an exception class for the RegAPI with values from get_error_codes, just to automate the error detection a little.