Plugins can be added to the ORM layer through the Xyster_Orm
instance which holds a plugin broker.
<?php $plugin = new MyOrmPlugin; Xyster_Orm::getInstance()->registerPlugin($plugin);
There are other plugin-related methods available on Xyster_Orm
.
getPlugin
: Gets the plugin of the specified type found or an array if more than one are registered
getPlugins
: Gets all registered plugins
hasPlugin
: Checks if a plugin of a certain class type has been registered
unregisterPlugin
: Removes the plugin specified or all plugins of the type specified
The methods of these plugins are called before and after certain events that occur to entities.
preDelete
: Before an entity is deleted
preInsert
: Before an entity is newly inserted into the data store
preUpdate
: Before an entity's changes are saved back to the data store
postDelete
: After an entity was deleted from the data store
postInsert
: After an entity is newly inserted into the data store
postLoad
: When an entity is created from a row in the data store (or retrieved from the secondary cache)
postUpdate
: After an entity's values were updated in the data store
Xyster includes a plugin for ACL registration and one for audit trail logging in its default distribution.
The first plugin included in the framework release is the Xyster_Orm_Plugin_Acl
; responsible for registering entities that implement Zend_Acl_Resource_Interface in a Zend_Acl
.
<?php $acl = new Xyster_Acl; $plugin = new Xyster_Orm_Plugin_Acl($acl); Xyster_Orm::getInstance()->registerPlugin($plugin);
When an entity is loaded from the data store or pulled from the secondary cache, the ACL plugin adds it to the Zend_Acl
provided to it if the entity has not already been added. Using this plugin lets the developer omit checking the ACL for the presence of an entity and adding it if absent.
The second plugin included in the framework release is the Xyster_Orm_Plugin_Log
; responsible for writing entity events to an audit trail.
<?php $log = new Zend_Log(/* with your options here */); $useAuth = true; /* whether to ask Zend_Auth who is authenticated */ $plugin = new Xyster_Orm_Plugin_Log($log, $useAuth); Xyster_Orm::getInstance()->registerPlugin($plugin);
When an entity is deleted, inserted, or updated, the plugin sends an entry to the Zend_Log
at the information level (Zend_Log::INFO
). As demonstrated above, the plugin can optionally get the current authenticated identity from Zend_Auth
. This plugin is useful for keeping security records of entity change events.