core/model/modx/registry/modfileregister.class.php
This file contains a simple file-based implementation of modRegister.
- Package
- modx
- Subpackage
- registry
\modFileRegister
A simple, file-based implementation of modRegister.
This implementation does not address transactional conflicts and should be used in non-critical processes that are easily recoverable.
- Parent(s)
- \modRegister
Properties

boolean
$__kill= 'false'
A polling flag that will terminate additional polling when true.
Inherited from: \modRegister::$$__killfalseDetails- Type
- boolean
- Inherited_from
- \modRegister::$$__kill

string
$_currentTopic= ''/''
An optional current topic to allow writes to relative paths.
Inherited from: \modRegister::$$_currentTopic'/'Details- Type
- string
- Access
- protected
- Inherited_from
- \modRegister::$$_currentTopic

string
$_key= 'null'
nullDetails- Type
- string
- Access
- protected
- Inherited_from
- \modRegister::$$_key

string
$directory= 'null'
A physical directory where the register stores topics and messages.
nullDetails- Type
- string

\modX
$modx= 'null'
A reference to the modX instance the register is loaded by.
Inherited from: \modRegister::$$modxnullDetails- Type
- \modX
- Access
- public
- Inherited_from
- \modRegister::$$modx

array
$options= 'null'
nullDetails- Type
- array
- Access
- public
- Inherited_from
- \modRegister::$$options

array
$subscriptions= 'array()'
An array of topics and/or messages the register is subscribed to.
Inherited from: \modRegister::$$subscriptionsarray()Details- Type
- array
- Access
- public
- Inherited_from
- \modRegister::$$subscriptions
Methods

__construct(
\modX $modx, string $key, array $options
=
array()
)
:
voidConstruct a new modFileRegister instance.
| Name | Type | Description |
|---|---|---|
| $modx | \modX | &$modx A reference to a modX instance. |
| $key | string | A valid PHP variable which will be set on the modRegistry instance. |
| $options | array | Optional array of registry options. |

_readMessage(
string $filename, boolean $remove
=
true
)
:
voidRead a message file from the queue.
| Name | Type | Description |
|---|---|---|
| $filename | string | An absolute path to a message file to read. |
| $remove | boolean | Indicates if the message file should be deleted once the message is read from it. |
- Access
- private
- Todo
- Implement support for reading various message types, other than executable PHP format.

abort(
$transactionKey
)
:
void| Name | Type | Description |
|---|---|---|
| $transactionKey |

acknowledge(
string $messageKey, string $transactionKey
)
:
void
| Name | Type | Description |
|---|---|---|
| $messageKey | string | The key of the message being read |
| $transactionKey | string | The secure key of the transaction that is reading |

begin(
\$transactionKey $transactionKey
)
:
void
| Name | Type | Description |
|---|---|---|
| $transactionKey | \$transactionKey | The key of the message |

close(
)
:
booleanClose the connection to the register service implementation.
| Type | Description |
|---|---|
| boolean | Indicates if the connection was closed successfully. |

commit(
string $transactionKey
)
:
void
| Name | Type | Description |
|---|---|---|
| $transactionKey | string | The key of the transaction |

connect(
array $attributes
=
array()
)
:
booleanMake sure the register can write to the specified $directory.
| Name | Type | Description |
|---|---|---|
| $attributes | array | A collection of attributes required for connection to the register. |
| Type | Description |
|---|---|
| boolean | Indicates if the connection was successful. |

getSortedDirectoryListing(
string $dir
)
:
arrayGet list of topic messages from a directory sorted by modified date.
| Name | Type | Description |
|---|---|---|
| $dir | string | A valid directory path. |
| Type | Description |
|---|---|
| array | An array of topic messages sorted by modified date. |

read(
array $options
=
array()
)
:
mixedReads any undigested messages from subscribed topics.
This implementation supports the following options and default behavior:
- msg_limit: Only poll until the specified limit of messages has been digested. Default is 5 messages.
- time_limit: Poll for new messages for a specified number of seconds. Default is the result of the php time_limit system variable.
- poll_limit: Only poll for new subscriptions a specified number of times. Default is unlimited.
- poll_interval: Wait a specified number of seconds between each additional polling iteration, after the initial one. Default is no interval.
- remove_read: Remove the message immediately upon digesting it. Default is true.
- include_keys: Include the message keys in the array of messages returned. Default is false.
| Name | Type | Description |
|---|---|---|
| $options | array | An array of general or protocol specific options. |
| Type | Description |
|---|---|
| mixed | The resulting message from the register. |

send(
string $topic, mixed $message, array $options
=
array()
)
:
booleanSend a message to the register.
This implementation provides support for sending messages using either time-based indexes so they are consumed in the order they are produced, or named indexes typically used when consumers want to subscribe to a specific, unique message. Individual messages or message collections passed in numerically indexed arrays are treated as time-based messages and message collections passed in associative arrays are treated as named messages. e.g., to send a single message as named, wrap it in an array with the intended message name as the key.
This implementation also supports a message_type option to indicate the format of the message being sent to the register. Currently only supports executable PHP format.
Other implementation specific options include:
- delay: Number of seconds to delay the message. This option is only supported for time-based messages.
- ttl: Number of seconds the message is valid in the queue. Default is forever or 0.
- kill: Tells a message consumer to stop consuming any more messages after reading any message sent with this option.
| Name | Type | Description |
|---|---|---|
| $topic | string | A topic container in which to broadcast the message. |
| $message | mixed | A message, or collection of messages to be sent to the register. |
| $options | array | An optional array of general or protocol specific message properties. |
| Type | Description |
|---|---|
| boolean | Indicates if the message was recorded. |
- Todo
- Implement support for sending various message types, other than executable PHP format.

setCurrentTopic(
string $topic
)
:
void
| Name | Type | Description |
|---|---|---|
| $topic | string | The key of the topic |

subscribe(
string $topic
)
:
booleanSubscribe to a topic (or specific message) in the register.
Inherited from: \modRegister::subscribe()| Name | Type | Description |
|---|---|---|
| $topic | string | The path representing the topic or message. |
| Type | Description |
|---|---|
| boolean | Indicates if the subscription was successful. |

unsubscribe(
string $topic
)
:
booleanUnsubscribe from a topic (or specific message) in the register.
Inherited from: \modRegister::unsubscribe()| Name | Type | Description |
|---|---|---|
| $topic | string | The path representing the topic or message. |
| Type | Description |
|---|---|
| boolean | Indicates if the subscription was removed successfully. |