core/model/modx/registry/modfileregister.class.php

Show: inherited
Table of Contents

This file contains a simple file-based implementation of modRegister.

Package
modx  
Subpackage
registry  

\modFileRegister

Package: modx\registry

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

Propertypublicboolean  $__kill= 'false'
inherited

A polling flag that will terminate additional polling when true.

Inherited from: \modRegister::$$__kill
Default valuefalseDetails
Type
boolean
Inherited_from
\modRegister::$$__kill  
Propertyprotectedstring  $_currentTopic= ''/''
inherited

An optional current topic to allow writes to relative paths.

Inherited from: \modRegister::$$_currentTopic
Default value'/'Details
Type
string
Access
protected  
Inherited_from
\modRegister::$$_currentTopic  
Propertyprotectedstring  $_key= 'null'
inherited

The key identifying this register in a registry.

Inherited from: \modRegister::$$_key
Default valuenullDetails
Type
string
Access
protected  
Inherited_from
\modRegister::$$_key  
Propertyprotectedstring  $directory= 'null'

A physical directory where the register stores topics and messages.

Default valuenullDetails
Type
string
Propertypublic\modX  $modx= 'null'
inherited

A reference to the modX instance the register is loaded by.

Inherited from: \modRegister::$$modx
Default valuenullDetails
Type
\modX
Access
public  
Inherited_from
\modRegister::$$modx  
Propertypublicarray  $options= 'null'
inherited

An array of global options applied to the registry.

Inherited from: \modRegister::$$options
Default valuenullDetails
Type
array
Access
public  
Inherited_from
\modRegister::$$options  
Propertypublicarray  $subscriptions= 'array()'
inherited

An array of topics and/or messages the register is subscribed to.

Inherited from: \modRegister::$$subscriptions
Default valuearray()Details
Type
array
Access
public  
Inherited_from
\modRegister::$$subscriptions  

Methods

methodpublic__construct( \modX $modx, string $key, array $options = array() ) : void

Construct a new modFileRegister instance.

Parameters
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.

methodprivate_readMessage( string $filename, boolean $remove = true ) : void

Read a message file from the queue.

Parameters
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.

Details
Access
private  
Todo
Implement support for reading various message types, other than executable PHP format.  
methodpublicabort(  $transactionKey ) : void
inherited

Inherited from: \modRegister::abort()
Parameters
Name Type Description
$transactionKey
methodpublicacknowledge( string $messageKey, string $transactionKey ) : void
inherited

Acknowledge the registry was read

Inherited from: \modRegister::acknowledge()
Parameters
Name Type Description
$messageKey string

The key of the message being read

$transactionKey string

The secure key of the transaction that is reading

methodpublicbegin( \$transactionKey $transactionKey ) : void
inherited

Begin the reading of the message

Inherited from: \modRegister::begin()
Parameters
Name Type Description
$transactionKey \$transactionKey

The key of the message

methodpublicclose( ) : boolean

Close the connection to the register service implementation.

Returns
Type Description
boolean Indicates if the connection was closed successfully.
methodpubliccommit( string $transactionKey ) : void
inherited

Commit the transaction and finish

Inherited from: \modRegister::commit()
Parameters
Name Type Description
$transactionKey string

The key of the transaction

methodpublicconnect( array $attributes = array() ) : boolean

Make sure the register can write to the specified $directory.

Parameters
Name Type Description
$attributes array

A collection of attributes required for connection to the register.

Returns
Type Description
boolean Indicates if the connection was successful.
methodpublicgetCurrentTopic( ) : string
inherited

Get the current topic of the register.

Inherited from: \modRegister::getCurrentTopic()
Returns
Type Description
string The current topic set for the register.
methodpublicgetKey( ) : string
inherited

Get the key of this registry

Inherited from: \modRegister::getKey()
Returns
Type Description
string The key of the current registry
methodprivategetSortedDirectoryListing( string $dir ) : array

Get list of topic messages from a directory sorted by modified date.

Parameters
Name Type Description
$dir string

A valid directory path.

Returns
Type Description
array An array of topic messages sorted by modified date.
methodpublicread( array $options = array() ) : mixed

Reads 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.
Parameters
Name Type Description
$options array

An array of general or protocol specific options.

Returns
Type Description
mixed The resulting message from the register.
methodpublicsend( string $topic, mixed $message, array $options = array() ) : boolean

Send 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.
Parameters
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.

Returns
Type Description
boolean Indicates if the message was recorded.
Details
Todo
Implement support for sending various message types, other than executable PHP format.  
methodpublicsetCurrentTopic( string $topic ) : void
inherited

Set the current topic to be read

Inherited from: \modRegister::setCurrentTopic()
Parameters
Name Type Description
$topic string

The key of the topic

methodpublicsubscribe( string $topic ) : boolean
inherited

Subscribe to a topic (or specific message) in the register.

Inherited from: \modRegister::subscribe()
Parameters
Name Type Description
$topic string

The path representing the topic or message.

Returns
Type Description
boolean Indicates if the subscription was successful.
methodpublicunsubscribe( string $topic ) : boolean
inherited

Unsubscribe from a topic (or specific message) in the register.

Inherited from: \modRegister::unsubscribe()
Parameters
Name Type Description
$topic string

The path representing the topic or message.

Returns
Type Description
boolean Indicates if the subscription was removed successfully.
Documentation was generated by DocBlox 0.18.1.