PHP Class izzum\statemachine\persistence\MongoDB

MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling. MongoDB obviates the need for an Object Relational Mapping (ORM) to facilitate development. start macosx: mongod --config /usr/local/etc/mongod.conf mongo shell: mongo
Inheritance: extends Adapter, implements izzum\statemachine\loader\Loader
Exibir arquivo Open project: rolfvreijdenberger/izzum-statemachine Class Usage Examples

Protected Properties

Property Type Description
$dns string the data source name for a mongo connection
$driver_options array the php driver specific options
$options array connection options

Public Methods

Method Description
__construct ( string $dns = 'mongodb://localhost:27017', array $options = ["connect" => true], array $driver_options = [] ) constructor. a connection to mongodb via the mongoclient will be lazily created.
__toString ( )
getClient ( ) : MongoClient Gets a lazy loaded \MongoClient instance.
getEntityIds ( $machine, $state = null ) {@inheritDoc}
isPersisted ( Identifier $identifier ) {@inheritDoc}
load ( StateMachine $statemachine ) {@inheritDoc} Load the statemachine via a document in a mongodb collection.
processGetState ( Identifier $identifier ) {@inheritDoc}
setClient ( MongoClient $client ) sets a mongoclient. this can be useful if your application already has a mongoclient instantiated and you want to reuse it.
toString ( )

Protected Methods

Method Description
addHistory ( Identifier $identifier, $state, $message = null, $is_exception = false ) {@inheritDoc}
checkAndCreateIndexesIfNecessary ( number $check_index_once_in = 1000 ) since we do not want to burden a client of this code with the responsiblity of creating indexes, we take a statistical approach to check if we need to create an index in the background. This will only be done once.
createIndexes ( ) create indexes in the background for the collections used. this will only be done by mongo if they do not exist already.
insertState ( Identifier $identifier, $state, $message = null ) {@inheritDoc}
onConnect ( ) A hook to use in a subclass.
updateState ( Identifier $identifier, $state, $message = null ) {@inheritDoc}

Method Details

__construct() public method

an existing mongoclient can also be set on this class (reuse a client accross your application)
public __construct ( string $dns = 'mongodb://localhost:27017', array $options = ["connect" => true], array $driver_options = [] )
$dns string the data source name. mongodb://[username:password@]host1[:port1][,host2[:port2:],...]
$options array server options (usable for authentication, replicasets etc)
$driver_options array php specifif driver options

__toString() public method

public __toString ( )

addHistory() protected method

{@inheritDoc}
protected addHistory ( Identifier $identifier, $state, $message = null, $is_exception = false )
$identifier izzum\statemachine\Identifier

checkAndCreateIndexesIfNecessary() protected method

since we do not want to burden a client of this code with the responsiblity of creating indexes, we take a statistical approach to check if we need to create an index in the background. This will only be done once.
protected checkAndCreateIndexesIfNecessary ( number $check_index_once_in = 1000 )
$check_index_once_in number check for index creation. on average, every times the index should be created if it is not there already

createIndexes() protected method

create indexes in the background for the collections used. this will only be done by mongo if they do not exist already.
protected createIndexes ( )

getClient() public method

Gets a lazy loaded \MongoClient instance.
public getClient ( ) : MongoClient
return MongoClient

getEntityIds() public method

{@inheritDoc}
public getEntityIds ( $machine, $state = null )

insertState() protected method

{@inheritDoc}
protected insertState ( Identifier $identifier, $state, $message = null )
$identifier izzum\statemachine\Identifier

isPersisted() public method

{@inheritDoc}
public isPersisted ( Identifier $identifier )
$identifier izzum\statemachine\Identifier

load() public method

The document, originally loaded as a json string (see JSON::getJSONSchema) is stored at the mongodb collection 'configuration' by default. multiple machine definitions can be provided in a single document, or in multiple documents in the collection. The first document containing the 'machines.name' key with the value matching the name of the $statemachine is used. You could use the ReaderWriterDelegator to use another source to load the configuration from.
public load ( StateMachine $statemachine )
$statemachine izzum\statemachine\StateMachine

onConnect() protected method

you can do you initial setup here if you like.
protected onConnect ( )

processGetState() public method

{@inheritDoc}
public processGetState ( Identifier $identifier )
$identifier izzum\statemachine\Identifier

setClient() public method

sets a mongoclient. this can be useful if your application already has a mongoclient instantiated and you want to reuse it.
public setClient ( MongoClient $client )
$client MongoClient

toString() public method

public toString ( )

updateState() protected method

{@inheritDoc}
protected updateState ( Identifier $identifier, $state, $message = null )
$identifier izzum\statemachine\Identifier

Property Details

$dns protected_oe property

the data source name for a mongo connection
protected string $dns
return string

$driver_options protected_oe property

the php driver specific options
protected array $driver_options
return array

$options protected_oe property

connection options
protected array $options
return array