Ukázková třída

Vytvářené objekty nemusí práci s DB vůbec řešit (nepotřebují-li speciální funkce/dotazy)

<?php
// Requirements
HF_Runtime::load("HF_DBObject");
HF_Runtime::load("HF_DBObjectFactory");

/**
 * Default factory class implementation
 *
 * @package    Example
 * @author    Tomas Kral
 * @version    1.0
 */
/* Pleas set class name */

class ClassNameFactory extends HF_DBObjectFactory {
    
/**
     * Set tables definition for the class
     *
     * @param array $dbTablesModel DB configuration
     */
    
protected $dbTablesModel = array(
                    
"table_name" => array(
                            
"PK" => array("id" => true),
                            
"id" => array("db_type" => "%d""attribute" => "id""regexp" => "^[0-9]+\$"),
                            
"table_attribute" => array("db_type" => "%s""attribute" => "objectAttribute""regexp" => "^(0|1){0,1}\$"),
                        ));


    
/**
     * Convert DB key to cache key<br />
     * !! Reimplement this method !!
     *
     * @param mixed $key Primary key of DB table
     *
     * @return Cache key string
     */
    
protected function keyToCacheKey($key) {
        if (!isset(
$key['part_key_a'])) $key['part_key_a'] = $key[0];
        if (!isset(
$key['part_key_b'])) $key['part_key_b'] = $key[1];
        return 
$this->objName."_".$key['part_key_a']."-".$key['part_key_b'];
    }


    
/******************************************************/
    // It's recomended to implement alsow this (but not required)

    /**
     * Set Db object for this class
     *
     * @param object $dbObject Object for working with DB
     */
    
protected static $dbObjectStatic;

    
/**
     * Sets Db object for this class
     *
     * @param object $dbObject Object for working with DB
     */
    
public static function setDbObject($dbObject) {
        
self::$dbObjectStatic $dbObject;
    }
}


/**
 * Default class implementation
 *
 * @package    Example
 * @author    Tomas Kral
 * @version    1.0
 */
/* Pleas set class name */

class ClassName extends HF_DBObject {
    protected static 
$dbObject;
    protected static 
$dbTablesModelStatic;

    
/**
     * Sets Db object for this class
     *
     * @param object $dbObject Object for working with DB
     */
    
public static function setDbObject($dbObject) {
        
self::$dbObject $dbObject;
    }

    
/**
     * Sets Db tables model for this class
     *
     * @param object $dbTablesModel Db tables model
     */
    
public static function setDbTablesModel($dbTablesModel) {
        
self::$dbTablesModelStatic $dbTablesModel;
    }


    
/**
     * Serialize support fix<br />
     * If needed add magic method <b>__wakeup</b> and method <b>filter_function</b>
     */

}
?>

13. 12. 2007 15:50 | Hopkins