This is a summary of the API methods that you would use for most of your tasks. The full API doc can be found here.
Object operations
Basic
All runtime calls are through the persistence manager (epManager). For most of the tasks, you need only six basic methods. They are -
- epObject create($class [, …])
- Description: creates a persistable object of a given class1)
- Parameter string $class: the class name
- Parameters […]: the constructor parameters for the class
- Return epObject: the persitable object created
- bool commit(epObject &$o)
- Description: commit a persistable object2)
- Parameter epObject &$o: the persistable object to be commmited
- Return boolean: true if successful; false if failed
- bool delete(epObject &$o)
- Description: delete a persistable object from both memory and datastore
- Parameter epObject &$o: the persistable object to be deleted
- Return boolean: true if successful; false if failed
- bool deleteAll($class)
- Description: delete all objects in a class
- Parameter string $class: the name of the class
- Return boolean: boolean
- bool refresh(epObject &$o)
- Description: refresh a persistable object from datastore (modified variable values are replaced with those in datastore)
- Parameter epObject &$o: the persistable object to be refreshed
- Return boolean: true if successful; false if failed
- false|array find(string|epObject $o)
Advanced
Apart from the above six basic methods, sometimes you might want to get all object in a class or if you want to change database at runtime, you can use
- false|array get($class)
- Description: Returns all objects in a class
- Parameter string: The name of a class for which you want to retrieve all its objects
- Return boolean: false (if failed) or array of objects found in datastore
- false|array setDsn($dsn [, …])
- Description: Switches database DSN at runtime for certain classes
- Parameter string $dsn: The target DSN you want to change to
- Parameters […]: The names of classes you want to change DSNs. If classes are unspecified, DSNs for all classes are changed.
- Return boolean: false if failed or true if succeeded
- array getQueries()
- Description: Returns all the queries logged. To log queries, turn on option ’log_queries’3).
- Return array: The array of queries keyed by the DSNs
Event listeners
The following is the event listener API on epManager. Please refer to Event listeners for more information.
- boolean register($l)
- Description: register an event listener with the manager
- Parameter: string|object $l the name of the listener class or a (global) listener instance
- Return: boolean
- integer unregister($l)
- Description: unregister (remove) an event listener instance of a listener class from the manager
- Parameter: string|object $l the name of the listener class or a (global) listener instance
- Return: false|integer (the number of global instances or local listener classes removed)
Transactions
The following are the API methods for transactions. Please refer to Transactions for more information.
- bool|epTransaction start_t()
- Description: Start a transaction
- Parameter: none
- Return: bool|epTransaction
- void commit_t(boolean $rollback = true)
- Description: End a transaction
- Parameter: epTransaction $t
- Parameter: boolean $rollback (default to true)
- Return: void
- Throws Exception
- void rollback_t()
- Description: Abort a transaction and rollback
- Parameter: epTransaction $t
- Return: void
log_queries = true
or programmatically add one line before any operations in your script
epManager::instance()->setConfigOption('log_queries', true);