Runtime API

Table of Contents

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)
    • Description: find persisted objects by an EZOQL query string or an example object
    • Parameter string|epObject $o: either an EZOQL query string or the example object
    • Return boolean: false (if failed) or array of objects found in datastore

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
1) If the class is persisted for the first time, EZPDO will auto-compile its source code if the <auto-compile> option is enabled in configuration.
2) If you enable the <auto-flush> option in your configuration file, all modified (’dirty’) objects in memory will be automatically commited before your script exits.
3) You could either insert a line in the config file

    log_queries = true

or programmatically add one line before any operations in your script

    epManager::instance()->setConfigOption('log_queries', true);

8 user comments

  1. EZPDO » Blog Archive » EZPDO in the last week on March 19th, 2005:

    […] e impressed by the ease in handling complex object relationships. Many find it easy to use the runtime API to manage objects, and the mini object query language, EZOQL, to search objects. Auto-compile and […]

  2. Sawi on January 27th, 2006:

    What about situation, when __construct has parameters and there can’t be default values?
    Function “create” calls my constructor without parameters - and it brings errors.

  3. ezpdo4php on January 27th, 2006:

    saws, you can put your params after the class name when calling epManager::create(). for example,
    $o = $m->create('MyClass', $param1, $param2, $param3);

    the params will then be passed to the constructor in your class. let us know if it works out for you.

  4. Sawi on January 30th, 2006:

    Hi!
    Thanks for help - it is enough for me.
    But I think You should place this info on this page in decsription of function “create”.

  5. ezpdo4php on February 3rd, 2006:

    Thankss Sawi. Now fixed.

  6. LoD on April 25th, 2006:

    IMHO, this page is sorely missing the following link :).
    http://www.ezpdo.net/docs/

    I only found it by searching, and it contains very useful information, e.g. on the epArray class.

  7. ezpdo4php on April 25th, 2006:

    Thanks LoD. Right to the point. The link is added now.

  8. Wilker Lúcio on December 6th, 2006:

    I have a sugestion for EZPDO, create a function like findOne, this function will return the first result of a Object Query or return null (if dont have any result). Its so simple, but so usefull to.

    I make one exemple implementation of this method (right, its not a best way to do this, but works), i using her while wait for a official implementation ^^

    public function &findOne() {
    $args = func_get_args();
    $result = call_user_func_array(array(&$this, ‘find’), $args);
    $obj = array_shift($result);

    return $obj;
    }

    Thanks for atemption.

Post your comments

XHTML: tags you can use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

Couldn't find your convert utility. Check that you have ImageMagick installed.