Skip to content

Api: MessageRegistry

Adrian edited this page Feb 28, 2024 · 4 revisions

at\peekaboo\MessageRegistry

static properties

  • MessageRegistry::$defaultLocale

    string $defaultLocale
    
    The locale to use if none is provided to message() or messageFrom(). Note, no validation is performed on the value set.

static methods

  • MessageRegistry::message()

    public static message( string $key, array $context, string $locale = null, string $group = "" ) : ? string
    

    Looks up and formats the message identified by key, using the given locale and context.

    • parameters:
      • string $key: Message identifier. This is a dot-delimited path for the message format to look up.
      • array $context: Formatting context, in key:value format. Non-scalar values will be encoded if possible.
      • ? string $locale: Target message locale
      • string $group: The bundle group name to look up the message format in
    • Throws MessageException MessageError::FormatFailed: On failure
    • Returns string | null: Formatted message on success; or null if message format is not found
  • MessageRegistry::messageFrom()

    public static message( ResourceBundle $messages, string $key, array $context, string $locale = null ) : ? string
    

    Looks up and formats the message identified by key, using the given locale and context, from the given bundle of messages.

    This method is the same as ::message(), but does not look in the message registry; it only uses the given bundle.

    • parameters:
      • ResourceBundle $messages: The messages bundle to look up format from
      • string $key: Message identifier. This is a dot-delimited path for the message format to look up.
      • array $context: Formatting context, in key:value format. Non-scalar values will be encoded if possible.
      • ? string $locale: Target message locale
    • Throws MessageException MessageError::FormatFailed: On failure
    • Returns string | null: Formatted message on success; or null if message format is not found
  • MessageRegistry::register()

    public static register( ResourceBundle $messages, string $group = "" ) : void
    

    Adds a resource bundle to the registry.

    • parameters:
      • ResourceBundle $messages: Message format patterns
      • string $group: The group name to register the bundle to. if omitted, uses the default group.
  • MessageRegistry::unregister()

    public static register( ResourceBundle $messages, string $group = "" ) : void
    

    Removes a resource bundle from the registry.

    • parameters:
      • ResourceBundle $messages: Message format patterns
      • string $group: The group name to unregister the bundle from. if omitted, uses the default group.