Re: intl/resourcebundle
| From: | Stanislav Malyshev | Date: | Tue, 15 Dec 2009 00:07:59 +0000 |
| Subject: | Re: intl/resourcebundle | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-6917@lists.php.net to get a copy of this message | ||
Hi!
I propose (and have now working) the following extension to intl:First of all, I think it's great that you want to work on this module, it was long on the TODO list. Do you have the code in public anywhere?
class ResourceBundle
--------------------
public function __construct(
string $bundlename,
[string $locale,
bool $fallback = true]
)
Most of other modules have locale as the first param. Default locale can be specified as Locale::DEFAULT_LOCALE.
@TODO: libicu has a quite peculiar systematic finding files. $ENV[ICU_DATA] has to be set for regular files; php_streams are currently not supported - they would have to be read into memory as a whole and the memory "given" to libicu. Better possibilities?I'm not very familiar with this part of ICU, but looks like udata_setAppData could be helpful. Also, env variable can be overridden by u_setDataDirectory() (though this one is not thread-safe, so we probably shouldn't use it).
I think returning the class makes a lot of sense for nested structures.URES_STRING => string (UTF-8) URES_BINARY => string (as-is, both should change in php6 of course...) URES_INT => integerURES_INTVECTOR => auto-keyed array of intsURES_ARRAY => class ResourceBundle URES_TABLE => class ResourceBundleI decided against returning php native types in the latter two cases, as in both cases the result might be a) huge and b) deeply nested.
I decided against allowing "ArrayAccess", as the function might be expensive. It is not a simple "lookup".I think this class should implement ArrayAccess - it looks natural, and I don't see how it's substantially more expensive than calling get. It looks much slicker though :) And also implement Iterator - or get_iterator() method in class entry.
public function length() rather self-explanatory.This may be better as count()? Though both are OK.
As for the iterator of ResourceBundle I decided against using the libicu iterator functions, as those don't respect order of entries.It must have some order, not? Is it that bad that it's better to have none? Anyway, I think the fact that you get all of them one by one may be more important than order... -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com