List Info

Thread: DAO.php




DAO.php
user name
2007-01-24 14:07:18
Update of /var/cvs/Geeklog-2.x/DAO
In directory iowaoutdoors:/tmp/cvs-serv24518

Added Files:
	DAO.php DAOInterface.php PropelDAO.php buildPackage.php 
	namedQueries.xsd package.xml 
Log Message:
Initial Import

--- NEW FILE: buildPackage.php ---
<?php
require_once 'PEAR/PackageFileManager2.php';

PEAR::setErrorHandling(PEAR_ERROR_DIE);
$packagexml = new PEAR_PackageFileManager2();

$packagexml->setOptions(
 array('baseinstalldir' => 'Geeklog/DAO',
  'packagedirectory' => 'C:Program FilesApache
GroupApache2htdocsProjectsDAO',
  'filelistgenerator' => 'file',
  'packagefile' => 'package.xml'
 )
);

 $packagexml->setPackage('DAO');
 $packagexml->setSummary('A Data Access Object (DAO)
Implementation in PHP');
 $packagexml->setDescription('This is a DAO
implementation in PHP with explicit support for Propel
    is part of the bigger Geeklog Framework');
 $packagexml->setChannel('pear.geeklog.net');
 $packagexml->setPackageType('php');
 
 $packagexml->setReleaseVersion('1.0.0');
 $packagexml->setAPIVersion('1.0');
 
 $packagexml->setReleaseStability('stable');
 $packagexml->setAPIStability('stable');
 
 $packagexml->setNotes('First Stable release.');
 $packagexml->addRelease(); // set up a release section
 
 $packagexml->setPhpDep('5.1.0');
 $packagexml->setPearinstallerDep('1.4.0a12');
 
 $packagexml->addPackageDepWithChannel( 'required',
'propel_runtime', 'pear.phpdb.org', '1.2.0RC1');
 $packagexml->addPackageDepWithChannel( 'required',
'creole', 'pear.phpdb.org', '1.1.0RC1');
 
 $packagexml->addMaintainer('lead', 'tony', 'Tony Bibbs',
'tonygeeklog.net');
 $packagexml->setLicense('PHP License', 'http://www.php.net/license
');
 
 $packagexml->generateContents(); // create the
<contents> tag
 
 $e = $packagexml->writePackageFile();
 
 if (PEAR::isError($e)) {
     throw new Exception("Unable to write package
file.", new Exception($e->getMessage()));
 }
 
?>
--- NEW FILE: PropelDAO.php ---
<?php

/* Reminder: always indent with 4 spaces (no tabs). */

/**
* Data Access Object
*/
require 'Geeklog/DAO/DAOInterface.php';

/**
 * This is the data access object.  It is the proxy used by
all business logic to interact with the 
 * database.
 *
 * The DAO layer allows a clean seperation between the
details of accessing data from the business 
 * logic so that the developers can concentrate on the
business solution instead of the data layer.
 *
 * author Tony Bibbs <tonygeeklog.net>
 * copyright 2006
 * version $Id: PropelDAO.php,v 1.1 2007/01/24 20:07:16
tony Exp $
 * todo Make use of the XSD
 *
 */
class Geeklog_DAO_PropelDAO implements
Geeklog_DAO_DAOInterface {
	/**
	* Handle to XML DOM used to parsed the named queries file
	* var DomDocument
	* access private
	*/
	private $dom = null;
	
	/**
	 * Full path to the named query file to use
	 * var string
	 * access private
	 */
	private $namedQueryFile = null;
	
	/**
	 * Name of the database we are using
	 * var string
	 * access private
	 */
	private $databaseName = null;
	
	/**
	 * Path to the Propel domain objects
	 * var string
	 * access private
	 */
	private $domainObjectsPath = null;
	
	/**
	 * Array of queries pulled form named query file
	 * var array
	 * access private
	 */
	private $queries = null;
	
	/**
	 * Indicate whether or not we were explicitly told to start
a transaction and have yet to
	 * rollback or commit it
	 * var boolean
	 * access private
	 *
	 */
	private $inTransaction = false;
	
	/**
	 * Constructor
	 *
	 * Constructor takes an array of configuration options
specific to this DAO implementation
	 *
	 * author Tony Bibbs <tonygeeklog.net>
	 * access public
	 * param array $options Array of configuration options
	 *
	 */
	public function __construct($options)
	{
	    if (!empty($options['namedQueryFile'])) {
    	    if (!file_exists($options['namedQueryFile'])) {
    	        throw new Exception('Invalid Named Query File
Given.  Got: ' 
    	           . $options['namedQueryFile']);
    	    }
	    }
	    $this->namedQueryFile = $options['namedQueryFile'];
	    $this->databaseName = $options['databaseName'];
	    $this->domainObjectsPath =
$options['pathDomainObjects'];
	}
	
	/**
	* Provides generic way to get the name of the database from
Propel
	*
	* author Tony Bibbs <tonygeeklog.net>
	* access private
	* return string Database Name
	* todo Need to consider how this would change if we had
more than one data
	* source.
	*
	*/
	private function getDatabaseName()
	{
		return $this->databaseName;
	}
	
	/**
	* Gets a creole connection object
	*
	* Provides generic way for developers to get a handle to a
connection
	* object should they need one.  Using this is discouraged
as most DB 
	* interaction should happen using this DAO layer with
Propel domain objects
	* or by using the support this class gives for named
queries
	*
	* author Tony Bibbs <tonygeeklog.net>
	* access public
	* return object database connection object
	*
	*/
	public function getConnection()
	{
		$this->con =
Propel::getConnection($this->getDatabaseName());
		return $this->con;
	}
	
	/**
	* Allows developers to start a database transaction
	*
	* NOTE: This class uses Propel so transactions occur if you
are using
	* the native Propel domain objects.  You should only use
this if you plan to 
	* do things in addition to or instead of using Propel
	*
	* author Tony Bibbs <tonygeeklog.net>
	* access public
	*
	*/
	public function beginTransaction()
	{
		if (!is_object($this->con)) {
			$this->getConnection();
		}
		
		$this->con->begin();
		$this->inTransaction = true;
	}
	
	/**
	 * Getter for inTransaction member
	 *
	 * author Tony Bibbs <tonygeeklog.net>
	 * access public
	 * return boolean True if we are in a transaction,
otherwise false
	 *
	 */
	public function inTransaction()
	{
	    return $this->inTransaction;
	}
	
	/**
	* Allows developers to commit a database transaction
	*
	* NOTE: This class uses Propel so transactions occur if you
are using
	* the native Propel domain objects.  You should only use
this if you plan to 
	* do things in addition to or instead of using Propel
	*
	* author Tony Bibbs <tonygeeklog.net>
	* access public
	*
	*/
	public function commit()
	{
		if (!is_object($this->con)) {
			$this->getConnection();
		}
		
		try {
			$this->con->commit();
			$this->inTransaction = false;
		} catch (PropelException $e) {
			$this->con->rollback();
			$this->inTransaction = false;
			throw $e;
		}
	}
	
	/**
	 * Rolls a transaction back
	 *
	 * author Tony Bibbs <tonygeeklog.net>
	 * access public
	 * 
	 */
	public function rollback()
	{	    
	    $this->con->rollback();
	    $this->inTransaction = false;
	}
	
	/**
	* Saves an propel domain object.
	*
	* Some may wonder why this DAO layer exists when Propel
does much of this.
	* The reason is, frankly, that the decision to use Propel
may change.  This
	* layer decreases the Propel dependent code that would be
in our commands and
	* views.
	*
	* author Tony Bibbs <tonygeeklog.net>
	* access public
	* param object $objToSave Propel domain object we want
to persist to the DB
	* 
	*/
	public function save(&$objToSave)
	{
		$objToSave->save();
	}
	
	/**
	 * Deletes a record (or records) represented by a Propel
domain object
	 *
	 * Some may wonder why this DAO layer exists when Propel
does much of this.
	 * The reason is, frankly, that the decision to use Propel
may change.  This
	 * layer decreases the Propel dependent code that would be
in our commands and
	 * views.
	 *
	 * author Tony Bibbs <tonygeeklog.net>
	 * access public
	 * param object $objToDelete Propel domain object we
want to delete from the the DB
	 *
	 */
	public function delete($objToDelete)
	{
	    if (!is_object($objToDelete)) {
            throw new Exception('You must provide a valid
Propel domain object');
        }
        
		// Should probably log something at some point
		$objToDelete->delete();
	}
	
	/**
	 * Runs a named query that will do a delete.  When possible
you should use domain
	 * objects (see delete() above) but this is nice when you
want to delete more than
	 * one object at a time
	 *
	 * author Tony Bibbs <tonygeeklog.net>
	 * access public
	 * param string $queryName Name of delete query to run
	 *
	 */
	public function deleteWithCondition($queryName,
$args=null)
	{
        $this->exec($queryName, $args);
	}

    /**
     * Executes an arbitrary Named Query, with optional
parameters.
     * This code was moved from deleteWithCondition so that

     * non-delete operations (e.g., non-O/R inserts)
     * have a clearer place to go.
     */    
    public function exec($queryName, $args = null) {
        // Compile queries (if needed)
        $this->compileQueries();

        if (empty($args)) {
            $args = array();
        }
        
        // Make sure we found the query
        if (empty($this->queries[$queryName])) {
            throw new Exception("Query name,
$queryName, not found in named query file, 
                $this->namedQueryFile");
        }
        
        $sql = $this->queries[$queryName]['sql'];
        $this->getConnection();
        $prepStmt =
$this->con->prepareStatement($sql);         
        $prepStmt->executeQuery($args, null);            
     
    }
	
	/** 
	 * Retreive the requested object
	 * 
	 * Takes a propel domain object with the Primary Key(s) set
and then retreieves the 
	 * object from the database.
	 *
	 * author Tony Bibbs <tonygeeklog.net
	 * access public
	 * param mixed $objToGet Propel domain object 
	 * return mixed fully populated Propel domain object
	 *
	 */
	public function get($objToGet)
	{
	    // Should proably log something at some point	
		$className = get_class($objToGet) . 'Peer';	
			
		if (!class_exists($className)) {
		    require $this->domainObjectsPath .
"$className.php";
		}
		
		$pkFields = (array) $objToGet->getPrimaryKey();
		
		$retObj = null;
		if (!is_null($pkFields) && sizeof($pkFields) >
0) {
		  $retObj =
call_user_func_array(array($className,'retrieveByPK'),
$pkFields);
		} 
		
		return $retObj;
	}
	
	/**
	* Searches the database and returns Propel domain
object(s)
	*
	* This uses the concept of named queries.  All queries will
go in an XML file and each query
	* can be one of two types: 1) Propel 2) SQL.  The first one
will use the built in criteria support
	* that Propel has.  The second will simply issue raw SQL. 
Named queries have many benefits:
	* 1) Prevents any SQL from being put in business or display
logic
	* 2) All SQL is in a single place.  This makes maintenance
easier (explained further down)
	* 3) Named queries are easily reused
	* 4) Using this XML format allows future modifications that
would allow us to create a 
	*    PHPUnit2 test script to regression test each and every
query with test criteria data (not
	*    yet implemented).
	*
	* author Tony Bibbs <tonygeeklog.net>
	* access public
	* param string $queryName Name of query to run
	* param array $args Criteria arguments
	* param int $page Page to get
	* param int $recordCount Records per page
	* return array Array of Propel domain objects
	* todo implement paging and the user of the
recordCount. Note that Propel has a paging class in
	* its /etc directory (Propel_Pager) or something like
that.
	*
	*/
	public function find($queryName, $args=null, $page=null,
$recordCount=null)
	{
		// Should log something here
		
		// Ensure arguments are in the right format
		if (!empty($args) AND !is_array($args)) {
		    throw new Exception('The find() method on the DAO
layer expects all SQL arguments
		        be wrapped up in an array');
		}
		
		// Compile queries (if needed)
		$this->compileQueries();
		
		// Make sure we found the query
        if (empty($this->queries[$queryName])) {
            throw new Exception("Query name,
$queryName, not found in named query file, 
                $this->namedQueryFile");
        }
           
    	// This implements queries using raw SQL
    	$propelPeer =
$this->queries[$queryName]['propelPeer'];
    	
    	// Ensure we got a valid Propel Peer name
    	if (!strstr($propelPeer,'Peer') and
empty($this->queries[$queryName]['columnArray'])) {
    	    throw new Exception('Invalid Propel Peer name
given.  Please double check the named query file');
    	}
    	
    	// Ensure the required model class is already defined.
    	if ($propelPeer AND !class_exists($propelPeer)) {
    	    $classToInclude =
str_replace('Peer','',$propelPeer);
    	    throw new Exception("Commands or views using
PropelDAO are responsible for 
    	       including the classes they need.  You forgot to
include $classToInclude");
    	}
    	
    	$sql = $this->queries[$queryName]['sql'];
    	$this->getConnection();
    	$prepStmt = $this->con->prepareStatement($sql);
    	
    	if ($propelPeer) {
    	    $result =
$prepStmt->executeQuery($args,ResultSet::FETCHMODE_NUM);
        	$parentObj = get_parent_class($propelPeer);
        	return
call_user_func_array(array($parentObj,'populateObjects'),
array($result));
    	} else {
    	    $columnArray =
$this->queries[$queryName]['columnArray'];        	    
    	    if (is_numeric($columnArray) OR
is_null(($columnArray))) {
    	       $result =
$prepStmt->executeQuery($args,ResultSet::FETCHMODE_NUM);
    	    } else {        	       
    	       $result =
$prepStmt->executeQuery($args,ResultSet::FETCHMODE_ASSOC)
;        	       
    	    }
    	    return $this->toArray($result, $columnArray);
    	}
	}
	
	/**
	 * Performs arbitrary searches
	 *
	 * Unlike the find() method, this method allows for the
dynamic assembly of a query's WHERE
	 * and ORDER BY clauses.  This is particularly useful to
search pages that may combine any
	 * numbeer of optional or required search criteria.
	 *
	 * author Tony Bibbs <tonygeeklog.net>
	 * access public
	 * param string $queryName Query to load and add
WHERE/ORDER BY clauses to
	 * param array $strictParams Array of
fieldname=>value entries.  Each entry will use the
	 * SQL equal operator.  Thus, firstName=>'Tony' would
product "firstName = 'Tony'" in the 
	 * WHERE clause
	 * param array $looseParams Array of fieldname=>value
entries.  Each entry will use the 
	 * SQL like operator. Thus, firstname=>'Tony' would
produce "firstName like '%Tony%'" in
	 * the WHERE clause
	 * param array $orderByParams Array of
fieldname=>order to put into the ORDER BY clause.  So,
	 * if you have
array('lastName'=>'desc','salary'=>'asc') you will
get:
	 * "ORDER BY lastName desc, salary asc"
	 * param string $logicalOperator Can be one of the
following: OR, AND.  It is used as the glue
	 * between the WHERE clause entries.  If you require a mix
of both, you are better just getting
	 * the connection object from the DAO and then construct
and run the SQL yourself.  Remember, 
	 * the guideline is to remove as much SQL from our
commands/views as possible.  But it is just
	 * a guidline
	 * param int $page Page number to retrieve (NOT YET
IMPLEMENTED)
	 * param int $recordCount Number of records to get (NOT
YET IMPLEMENTED)
	 * return mixed Array of domain objects
	 * todo Implement paging and limiting
	 * todo this essentially does string manipulation
instead of using a prepared statement.  This
	 * is a serious security issue that needs to be addressed.
	 *
	 */
	public function search($queryName, $strictParams,
$looseParams, $orderByParams = null, 
	   $logicalOperator = 'OR', $page = null, $recordCount =
null)
	{
	    $whereArray = array();
	    $orderByArray = array();
	    
	    $args = array();
	    if (is_array($strictParams)) {
    	    foreach ($strictParams as
$fieldName=>$valueToUse) {
    	        $whereArray[] = "($fieldName = ?)";
    	        $args[] = $valueToUse;
    	    }
	    }
	    
	    if (is_array($looseParams)) {	        
    	    foreach ($looseParams as
$fieldName=>$valueToUse) {
    	        $whereArray[] = "($fieldName like
?)";
    	        $args[] = "%$valueToUse%";
    	    }
	    }
	    	    
	    // Make sure we got something in the WHERE clause
	    if (count($whereArray) == 0) {
	        throw new Exception('You did not pass strictParams
or looseParms.  One of them
                is required in order to run your search');
	    }
	    $whereClause = ' WHERE ' . implode("
$logicalOperator ", $whereArray);
	    
	    if (is_array($orderByParams)) {
    	    foreach ($orderByParams as
$fieldName=>$sortOrder) {
    	        $orderByArray[] = "$fieldName
$sortOrder";
    	    }
	    }
	    
	    // Since an order by is optional, only build it if you
got something<br>
        $orderByClause = '';
	    if (count($orderByArray) > 0) {
	       $orderByClause = ' ORDER BY ' . implode(",
", $orderByArray);
	    }
	    
	    // Compile queries (if needed)
		$this->compileQueries();
		
		// Make sure we found the query
        if (empty($this->queries[$queryName])) {
            throw new Exception("Query name,
{$queryName}, not found in named query file");
        }
           
    	// This implements queries using raw SQL
    	$propelPeer =
$this->queries[$queryName]['propelPeer'];
    	
    	// Ensure we got a valid Propel Peer name
    	if (!strstr($propelPeer,'Peer') and
empty($this->queries[$queryName]['columnArray'])) {
    	    throw new Exception('Invalid Propel Peer name
given.  Please double check the named query file');
    	}
    	
    	// Ensure the required model class is already defined.
    	if ($propelPeer AND !class_exists($propelPeer)) {
    	    $classToInclude =
str_replace('Peer','',$propelPeer);
    	    throw new Exception("Commands or views using
PropelDAO are responsible for 
    	       including the classes they need.  You forgot to
include $classToInclude");
    	}
    	
    	// Get query
    	$sql = $this->queries[$queryName]['sql'];
    	
    	// Add WHERE and ORDER BY clauses
    	$sql = $sql . $whereClause . $orderByClause;
    	
    	// Prepare the SQL.  NOTE: we have to use a prepared
statement to avoid having to detect
    	// data types.
    	$this->getConnection();
    	$prepStmt = $this->con->prepareStatement($sql);
    	
    	if ($propelPeer) {
    	    $result =
$prepStmt->executeQuery($args,ResultSet::FETCHMODE_NUM);
        	$parentObj = get_parent_class($propelPeer);
        	return
call_user_func_array(array($parentObj,'populateObjects'),
array($result));
    	} else {
    	    $columnArray =
$this->queries[$queryName]['columnArray'];        	    
    	    if (is_numeric($columnArray) OR
is_null(($columnArray))) {
    	       $result =
$prepStmt->executeQuery($args,ResultSet::FETCHMODE_NUM);
    	    } else {        	       
    	       $result =
$prepStmt->executeQuery($args,ResultSet::FETCHMODE_ASSOC)
;        	       
    	    }
    	    return $this->toArray($result, $columnArray);
    	}
	}
	
	/**
	 * In the rare cases we run SQL that returns data that
doesn't map to a domain object, this method
	 * can be used to return an array of values for the
columnArray attribute given
	 *
	 * author Tony Bibbs
	 * access private
	 * param ResultSet $creoleResultSet Creole ResultSet
object
	 * param mixed $columnToGet Can be a column name or
index
	 * return array Array of values for the given column
	 *
	 */	 
	public function toArray($creoleResultSet, $columnToGet)
	{
	    $retArray = array();
	    while($creoleResultSet->next()) {
          $retArray[] = 
$creoleResultSet->getString($columnToGet);
        }
        return $retArray;
	}
	
	/**
	 * Compiles the named query file
	 *
	 * The XML-based named query file is great as it allows us
to apply a schema to validate it, 
	 * however, we don't want to incur the cost of accessing
the file *and* parsing it for each and
	 * every query made.  To get around this, this method will
compile the named query file into a
	 * PHP file that contains an array representation of the
XML.  
	 *
	 * NOTE: this method assumes that a directory will not have
more than one named query file in
	 * it.  The destination of the compiled file will be in the
same directory as the named query
	 * file and it will be called compiledQueries.php
	 *
	 * author Tony Bibbs <tonygeeklog.net>
	 * access public
	 * todo Get rid of one named query file per directory
(i.e. name compiled file name unique)
	 * 
	 */
	private function compileQueries()
	{
	    // First determine of compilation is needed now.
	    $needsCompile = false;
		$arrayFileName = dirname($this->namedQueryFile) .
'/compiledQueries.php';
        if (file_exists($arrayFileName)) {
            if (filemtime($arrayFileName) <
filemtime($this->namedQueryFile)) {
                $needsCompile = true;
            }
        } else {
            $needsCompile = true;
        }
        if (!$needsCompile) {   
            // File is already compiled, bail
            require "$arrayFileName";
            return;
        }    		
	    
        // Parse named query XML and build arrray
	    $this->dom = new DomDocument();
		$this->dom->load($this->namedQueryFile);
		$xpath = new DOMXPath($this->dom);
		$queryList = $xpath->query('/named_queries/query'); 
		$queryArray = array();   
		foreach ($queryList as $curQuery) {
		    $queryName = $curQuery->getAttribute('name');
	        // Handle raw SQL query
	        $sqlList =
$xpath->query("/named_queries/query[name='$queryName']/sql");
	        $sql = $sqlList->item(0);
	        $propelPeer = $sql->getAttribute('propelPeer');
	        $columnArray =
$sql->getAttribute('columnArray');
	        $sqlStmt = $sql->textContent;
	        $queryArray[$queryName] =
array('propelPeer'=>$propelPeer,
	                                       
'columnArray'=>$columnArray,
	                                       
'sql'=>$sqlStmt);		         
		}
		
		// 'Compile' the array by putting it into a PHP file
		file_put_contents($arrayFileName, 
            '<?php $this->queries = ' .
var_export($queryArray, true) . '; ?>');
        $this->queries = $queryArray;        
	}
	
	public function &getPKNames(&$obj) {
		$dbKeys = $obj->buildPkeyCriteria()->keys();
		foreach ($dbKeys as $key) {
		    $phpKeyFieldNames[$this->getPhpFieldName($obj,
$key)] = $key;
		}
		return $phpKeyFieldNames;
	}
	
	private function &getPhpFieldName(&$obj, $colName)
{
	    $phpFieldName =
$obj->getPeer()->translateFieldName(
	           $colName, BasePeer::TYPE_COLNAME, 
	           BasePeer::TYPE_PHPNAME);
	    return strtolower(substr($phpFieldName, 0, 1)) .
substr($phpFieldName, 1);
	}
}

?>
--- NEW FILE: DAO.php ---
<?php

/* Reminder: always indent with 4 spaces (no tabs). */

/**
 * DAO Factory
 *
 * This file builds DAO objects
 *
 * author Tony Bibbs <tonygeeklog.net>
 * copyright 2006
 * version $Id: DAO.php,v 1.1 2007/01/24 20:07:16 tony
Exp $
 *
 */
class Geeklog_DAO {
    /**
     * Builds an instance of requested DAO object
     *
     * NOTE: the factory assume that if you don't send in
DAO options that you have defined your
     * default options in a constants as listed
     * 
     * author Tony Bibbs <tonygeeklog.net>
     * access public
     * static 
     * param array $options Override default DAO options by
passing them here
     * return Geeklog_PropelDAO Only DAO implementation at
this time
     * see Geeklog_DAO::singleton
     * todo When we add other DAO alternatives we can stop
hardcoding paths, etc but until then
     * let's avoid the hassle.
     *
     */
	public static function &factory($options = array())
	{
		if (count($options) == 0) {
		    $options = array('databaseName' =>
GEEKLOG_DAO_DBNAME,
		                     'namedQueryFile' =>
GEEKLOG_DAO_NAMEDSQL,
		                     'pathDomainObjects' =>
GEEKLOG_DAO_PROPEL_PATH
		                     );
		}
		
		$fileToInclude = 'Geeklog/DAO/PropelDAO.php';
		if (include_once($fileToInclude)) {
			$nameOfClass = 'Geeklog_DAO_PropelDAO';
			return new $nameOfClass($options);
        }
	}
	
	/**
     * Grabs a single instance of requested DAO object. 
     *
     * This differs from factory method above in that this
will not create a new instance of a DAO 
     * object unless the configuration options differ. 
Generally, this method should be used over
     * singleton
     *
     * author Tony Bibbs <tonygeeklog.net>
     * access public
     * static 
     * param array $options Override default DAO options by
passing them here
     * return Geeklog_PropelDAO Only DAO implementation at
this time
     * see Geeklog_DAO::factory
     *
     */
	public static function &singleton($options = array())
	{
		static $instances;
		
		if (!isset($instances)) {
            $instances = array();
        }
        
        $hash = serialize($options);
        
        if (!isset($instances[$hash])) {
            $instances[$hash] =
&self::factory($options);
        }

        return $instances[$hash];
	}
}

?>
--- NEW FILE: DAOInterface.php ---
<?php

/* Reminder: always indent with 4 spaces (no tabs). */

/**
 * The DAO Interface
 *
 * Defines how our DAO implementations should look
 *
 * author Tony Bibbs <tonygeeklog.net>
 * copyright 2006
 * version $Id: DAOInterface.php,v 1.1 2007/01/24
20:07:16 tony Exp $
 * todo Implement use of MAX_RESULTS
 * 
 */
interface Geeklog_DAO_DAOInterface {
	const MAX_RESULTS = 500;
	public function save(&$objToSave);
	public function delete($objToDelete);
	public function deleteWithCondition($queryName, $args =
null);
	public function get($objToGet); // object with only PK set
	public function find($queryName, $args=null, $page = null,
$recordCount = null);
	//public function search($queryName, $strictParams,
$looseParams, $looseParamTrail = null, 
	//	$page = null, $recordCount = null);
	public function search($queryName, $strictParams,
$looseParams, $orderByParams = null, 
	   $logicalOperator = 'OR', $page = null, $recordCount =
null);
	public function beginTransaction();
	public function rollback();
	public function commit();	
	public function &getPKNames(&$obj);
}

?>
--- NEW FILE: package.xml ---
<?xml version="1.0"
encoding="UTF-8"?>
<package packagerversion="1.4.11"
version="2.0" xmlns="http://pear
.php.net/dtd/package-2.0" xmlns:tasks="http://pear.p
hp.net/dtd/tasks-1.0" xmlnssi=&q
uot;http:
//www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pear.php.net
/dtd/tasks-1.0
    http://pear.php
.net/dtd/tasks-1.0.xsd
    http://pear.php.n
et/dtd/package-2.0
    htt
p://pear.php.net/dtd/package-2.0.xsd">
 <name>DAO</name>
 <channel>pear.geeklog.net</channel>
 <summary>A Data Access Object (DAO) Implementation in
PHP</summary>
 <description>This is a DAO implementation in PHP with
explicit support for Propel
    is part of the bigger Geeklog
Framework</description>
 <lead>
  <name>Tony Bibbs</name>
  <user>tony</user>
  <email>tonygeeklog.net</email>
  <active>yes</active>
 </lead>
 <date>2006-10-17</date>
 <time>11:03:35</time>
 <version>
  <release>1.0.0</release>
  <api>1.0</api>
 </version>
 <stability>
  <release>stable</release>
  <api>stable</api>
 </stability>
 <license uri="http://www.ph
p.net/license">PHP License</license>
 <notes>First Stable release.</notes>
 <contents>
  <dir baseinstalldir="Geeklog/DAO"
name="/">
   <file baseinstalldir="Geeklog/DAO"
md5sum="5dd6275a35df1976a89935d98f907f4d"
name="buildPackage.php" role="php"
/>
   <file baseinstalldir="Geeklog/DAO"
md5sum="45a1e3e275b7c872a468f4e5afa10fa7"
name="DAO.php" role="php" />
   <file baseinstalldir="Geeklog/DAO"
md5sum="ec6e693bcece2fb899d1aaef71da2e6c"
name="DAOInterface.php" role="php"
/>
   <file baseinstalldir="Geeklog/DAO"
md5sum="cb26c8101c88228d18fce3f3ffea4a7f"
name="namedQueries.xsd" role="data"
/>
   <file baseinstalldir="Geeklog/DAO"
md5sum="8449f9d84c05f16d43e71dddd3350291"
name="PropelDAO.php" role="php" />
  </dir>
 </contents>
 <dependencies>
  <required>
   <php>
    <min>5.1.0</min>
   </php>
   <pearinstaller>
    <min>1.4.0a12</min>
   </pearinstaller>
   <package>
    <name>propel_runtime</name>
    <channel>pear.phpdb.org</channel>
    <min>1.2.0RC1</min>
   </package>
   <package>
    <name>creole</name>
    <channel>pear.phpdb.org</channel>
    <min>1.1.0RC1</min>
   </package>
  </required>
 </dependencies>
 <phprelease />
 <changelog>
  <release>
   <version>
    <release>1.0.0</release>
    <api>1.0</api>
   </version>
   <stability>
    <release>stable</release>
    <api>stable</api>
   </stability>
   <date>2006-10-17</date>
   <license uri="http://www.ph
p.net/license">PHP License</license>
   <notes>First Stable release.</notes>
  </release>
 </changelog>
</package>

--- NEW FILE: namedQueries.xsd ---
<?xml version="1.0"?>
<xsd:schema xmlnssd=&q
uot;http://www
.w3.org/2001/XMLSchema">
    <xsd:element name="named_queries"
type="configType" />
    <xsd:complexType name="configType">
        <xsd:sequence>
            <xsd:element name="query"
type="queryType" minOccurs="0"
maxOccurs="unbounded" />
        </xsd:sequence>    
    </xsd:complexType>
    <xsd:complexType name="queryType">
        <xsd:sequence>
            <xsd:element name="sql"
type="sqlType" minOccurs="1"
maxOccurs="1" />
            <xsd:element name="test_parm"
type="parmType" minOccurs="0"
maxOccurs="unbounded" />
        </xsd:sequence>        
        <xsd:attribute name="name"
type="xsd:string" />
    </xsd:complexType>
    <xsd:complexType name="sqlType">
        <xsd:simpleContent>
            <xsd:extension
base="xsd:string">
                <xsd:attribute
name="propelPeer" type="xsd:string"
/>
                <xsd:attribute
name="columnArray" type="xsd:string"
/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>
    <xsd:complexType name="parmType">
        <xsd:simpleContent>
            <xsd:extension base="xsd:string"
/>
        </xsd:simpleContent>
    </xsd:complexType>
</xsd:schema>
_______________________________________________
geeklog2-cvs mailing list
geeklog2-cvslists.geeklog.net
http://lists.geeklog.net/mailman/listinfo/geeklog2-cvs


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )