Constants

CALLBACK_POSITION_PREPEND

CALLBACK_POSITION_PREPEND

CALLBACK_POSITION_APPEND

CALLBACK_POSITION_APPEND

Properties

$terminateCallbackChain

$terminateCallbackChain : boolean

Determines if the current callback-chain should be terminated at the next iteration

Type

boolean

$inCallbackChain

$inCallbackChain : boolean

Callback execution status

Type

boolean

$messageSearchers

$messageSearchers : array<mixed,callable>

Type

array<mixed,callable>

$missingMessageHandlers

$missingMessageHandlers : array<mixed,callable>

Type

array<mixed,callable>

$fetchedMessages

$fetchedMessages : array

Type

array

Methods

terminateCallbackChain()

terminateCallbackChain() 

Terminate callback chain from inside a callback

This method may be called from inside of a callback chain to break out in the next iteration *

Throws

\LogicException

Thrown if no callback chain is executing when called

addMissingMessageHandler()

addMissingMessageHandler(callable  $locator, integer  $position = self::CALLBACK_POSITION_APPEND) : $this

Append a function to handle missing messages.

The callbacks given to this method is executed when the corresponding MessageLocator could not find a valid message for a given id. The callback should return a string. The callback may also prevent return false to allow subsequent callbacks to execute. $locator->addMissingMessageHandler(function($msgId, MessageLocator $locator) {

if(MyOwnLocator::canLocate($msgId)) {
    return $msg;
}
$locator->terminateCallbackChain();

});

Parameters

callable $locator
integer $position

Returns

$this

messageExists()

messageExists(string|integer  $messageId) : boolean

Parameters

string|integer $messageId

Throws

\Exception

Returns

boolean

getMessage()

getMessage(integer|string  $messageId, boolean  $ignoreCachedEntries = false) : string|null

Parameters

integer|string $messageId
boolean $ignoreCachedEntries

Throws

\Exception

Returns

string|null

getMessageWithInfo()

getMessageWithInfo(integer|string  $messageId, boolean  $ignoreCachedEntries = false) : array

Parameters

integer|string $messageId
boolean $ignoreCachedEntries

Returns

array

fromJsonFile()

fromJsonFile(  $file) 

Parameters

$file

fromArray()

fromArray(  $array) : static

Parameters

$array

Returns

static

addMessageSearcher()

addMessageSearcher(callable  $searcher, integer  $position = self::CALLBACK_POSITION_APPEND) : $this

Parameters

callable $searcher
integer $position

Returns

$this

clearInstanceCache()

clearInstanceCache() 

offsetExists()

offsetExists(string|integer  $id) : boolean

OffsetExists Whether a message with the given id can be found without invoking missing message handlers

Parameters

string|integer $id

message id

Returns

boolean —

true on success or false on failure.

offsetGet()

offsetGet(string|integer  $id) : string

OffsetGet This method proxies ::getMessage($offset)

Parameters

string|integer $id

the id to retrieve

Returns

string —

the message template

offsetSet()

offsetSet(null  $offset, callable  $value) 

Appends a new message searcher Only the following syntax is valid: `$locator[] = function($id, $locator) {};

Parameters

null $offset
callable $value

Throws

\InvalidArgumentException

Exception is thrown if an offset is specified or the value is not callable

offsetUnset()

offsetUnset(mixed  $offset) 

Parameters

mixed $offset

Throws

\RuntimeException

Is always thrown as this operation is not supported

inCallbackChain()

inCallbackChain(boolean  $areWeInCallbackChain) 

Modify the status of current callback execution

This method can be used by the callback calling code to make sure other methods react properly.

Parameters

boolean $areWeInCallbackChain

Set the status of the callback chain execution

isCallbackChainToBeTerminated()

isCallbackChainToBeTerminated() : boolean

Get the status of the callback chain termination

This method can be used to determine if the callback chain is to be terminated prematurely.

Returns

boolean

markCallbackChainTerminated()

markCallbackChainTerminated() 

Mark callback chain terminated

This method should be called after the callback chain was terminated, either by breaking out of it prematurely or after finishing all callback handlers.

fetchMessage()

fetchMessage(string|integer  $messageId, boolean  $runMissingMessageHandlers = true) : array|boolean

Parameters

string|integer $messageId
boolean $runMissingMessageHandlers

Throws

\Exception

Returns

array|boolean

validateMessageId()

validateMessageId(string|integer  $mId) : boolean

Parameters

string|integer $mId

Returns

boolean