Class PHRUTS_PropertyMessageResources

Description

Concrete subclass of PHRUTS_MessageResources that reads message keys and corresponding strings from named property resources.

The config property defines the base property resource name, and must be specified.

IMPLEMENTATION NOTE: This class trades memory for speed by caching all messages located via generalizing the PHRUTS_Locale under the original locale as well. This results in specific messages being stored in the message cache more than once, but improves response time on subsequent requests for the same locale + key combination.

This class searches for a message key for property resources in the following sequence:

   config + "_" + localeLanguage + "_" + localeCountry + "_" + localeVariant
   config + "_" + localeLanguage + "_" + localeCountry
   config + "_" + localeLanguage
   config + "_" + default locale
   config

  • author: John WILDENAUER <jwilde@users.sourceforge.net> (PHP4 port of Struts)
  • author: Olivier HENRY <oliv.henry@gmail.com> (PHP5 port of Struts)
  • version: $Id: PHRUTS_PropertyMessageResources.php,v 1.3 2008/05/28 16:13:22 ohenry Exp $
  • copyright: Copyright PHruts 2008

Located in /util/PHRUTS_PropertyMessageResources.php (line 50)

PHRUTS_MessageResources
   |
   --PHRUTS_PropertyMessageResources
Variable Summary
array $locales
array $messages
Method Summary
PHRUTS_PropertyMessageResources __construct (string $config, [boolean $returnNull = false])
string findMessage (PHRUTS_Locale $locale, string $key, string $originalKey)
string findMessageByLocaleKey (string $localeKey, string $key, string $originalKey)
string getBaseMessage (PHRUTS_Locale $locale, string $key)
void loadLocale (string $localeKey)
Variables
array $locales = array() (line 57)

The set of locale keys for which we have already loaded messages, keyed by the value calculated in localeKey method.

  • access: protected
array $messages = array() (line 65)

The cache of messages we have accumulated over time, keyed by the value calculated in messageKey method.

  • access: protected

Inherited Variables

Inherited from PHRUTS_MessageResources

PHRUTS_MessageResources::$config
PHRUTS_MessageResources::$defaultLocale
PHRUTS_MessageResources::$formats
PHRUTS_MessageResources::$log
PHRUTS_MessageResources::$returnNull
Methods
Constructor __construct (line 76)

Construct a new PHRUTS_PropertyMessageResources according to the specified parameters.

  • access: public
PHRUTS_PropertyMessageResources __construct (string $config, [boolean $returnNull = false])
  • string $config: The configuration parameter for this PHRUTS_MessageResources.
  • boolean $returnNull: The returnNull property we should initialize with

Redefinition of:
PHRUTS_MessageResources::__construct()
Construct a new PHRUTS_MessageResources according to the specified parameters.
findMessage (line 206)

Returns a text message for the specified key, for the specified PHRUTS_Locale.

A null string result will be returned by this method if no relevant message resource is found. This method searches through the locale hierarchy (i.e. variant --> language --> country) for the message.

  • return: Text message for the specified key and locale
  • access: private
string findMessage (PHRUTS_Locale $locale, string $key, string $originalKey)
  • PHRUTS_Locale $locale: The requested message PHRUTS_Locale
  • string $key: The message key to look up
  • string $originalKey: The original message key to cache any found message under
findMessageByLocaleKey (line 246)

Returns a text message for the specified key, for the specified PHRUTS_Locale.

A null string result will be returned by this method if no relevant message resource is found.

  • return: Text message for the specified key and locale
  • access: private
string findMessageByLocaleKey (string $localeKey, string $key, string $originalKey)
  • string $localeKey: The requested key of the PHRUTS_Locale
  • string $key: The message key to look up
  • string $originalKey: The original message key to cache any found message under
getBaseMessage (line 96)

Returns a text message for the specified key, for the specified PHRUTS_Locale.

A null string result will be returned by this method if no relevant message resource is found for this key or PHRUTS_Locale, if the returnNull property is set. Otherwise, an appropriate error message will be returned.

  • access: protected
string getBaseMessage (PHRUTS_Locale $locale, string $key)
  • PHRUTS_Locale $locale: The requested message PHRUTS_Locale
  • string $key: The message key to look up

Redefinition of:
PHRUTS_MessageResources::getBaseMessage()
Returns a text message for the specified key and the specified PHRUTS_Locale.
loadLocale (line 146)

Load the messages associated with the specified PHRUTS_Locale key.

For this implementation, the config property should contain a fully qualified package and resource name, separated by periods, of a series of property resources to be loaded from the class loader that created this PHRUTS_PropertyMessageResources instance.

  • access: protected
void loadLocale (string $localeKey)
  • string $localeKey: The locale key for the messages to be retrieved

Inherited Methods

Inherited From PHRUTS_MessageResources

PHRUTS_MessageResources::__construct()
PHRUTS_MessageResources::formatMessage()
PHRUTS_MessageResources::getBaseMessage()
PHRUTS_MessageResources::getConfig()
PHRUTS_MessageResources::getMessage()
PHRUTS_MessageResources::getReturnNull()
PHRUTS_MessageResources::isPresent()
PHRUTS_MessageResources::localeKey()
PHRUTS_MessageResources::messageKey()
PHRUTS_MessageResources::messageKeyByLocaleKey()
PHRUTS_MessageResources::setReturnNull()
PHRUTS_MessageResources::__wakeup()

Documentation generated on Sat, 31 May 2008 15:46:28 +0200 by phpDocumentor 1.4.1