Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
<?php // +---------------------------------------------------------------------------+ // | This file is part of the Agavi package. | // | Copyright (c) 2003-2006 the Agavi Project. | // | | // | For the full copyright and license information, please view the LICENSE | // | file that was distributed with this source code. You can also view the | // | LICENSE file online at http://www.agavi.org/LICENSE.txt | // | vi: set noexpandtab: | // | Local Variables: | // | indent-tabs-mode: t | // | End: | // +---------------------------------------------------------------------------+ /** * An Agavi Database ORM for Doctrine, derived from the native PDO driver. * * * @package agavi * @subpackage database * * @author Ross Lawley <ross.lawley@gmail.com> * @since 0.9.0 * * @version $Id$ */ class AgaviDoctrineDatabase extends AgaviDatabase { /** * Stores the actual AgaviDatabase implementation (AgaviCreoleDatabase or * AgaviPdoDatabase). * * @var AgaviDatabase The AgaviDatabase instance used internally. * * @since 0.11.0 */ protected $agaviDatabase = null; /** * Stores the actual AgaviDatabase connection * * @var AgaviDatabase The AgaviDatabase instance used internally. * * @since 0.11.0 */ protected $connection = null; /** * Connect to the database. * * * @throws <b>AgaviDatabaseException</b> If a connection could not be * created. * * @author Ross Lawley <ross.lawley@gmail.com> * @since 0.11.0 */ public function connect() { try { // determine how to get our settings $method = $this->getParameter('method', 'normal'); switch ($method) { case 'normal': $runtime = AgaviConfigHandler::replaceConstants($this->getParameter('config', null)); break; case 'server': $runtime = $_SERVER[$this->getParameter('config')]; break; case 'env': $runtime = $_ENV[$this->getParameter('config')]; break; default: $error = 'Invalid DoctrineDatabase parameter retrieval method "%s"'; $error = sprintf($error, $method); throw new AgaviDatabaseException($error); } $dsn = $this->getParameter('dsn'); if($dsn == null) { // missing required dsn parameter $error = 'Database configuration specifies method "dsn", but is missing dsn parameter'; throw new AgaviDatabaseException($error); } $this->agaviDatabase = new Doctrine_Db($dsn); $this->connection = Doctrine_Manager::connection($this->agaviDatabase); $this->resource =& $this->manager; } catch( Doctrine_Db_Exception $e) { // the connection's foobar'd throw new AgaviDatabaseException($e->getMessage ()); } } /** * Initialize Doctrine set the autoloading * * @param AgaviDatabaseManager The database manager of this instance. * @param array An associative array of initialization parameters. * * @author Ross Lawley <ross.lawley@gmail.com> * @since 0.11.0 */ public function initialize(AgaviDatabaseManager $databaseManager, array $parameters = array()) { parent::initialize($databaseManager, $parameters); // get doctrine class path $classPath = AgaviConfigHandler::replaceConstants($this->getParameter('classpath',null)); // set the include path to our Propel generated classes if(!is_null($classPath)) { require($classPath); } else { require(AgaviConfig::get('core.lib_dir').'/Doctrine.php'); } spl_autoload_register(array('Doctrine', 'autoload')); spl_autoload_register(array($this, 'autoload')); } /** * Autoloading function for Doctrine Models * * @param string The name of the class to autoload. * * @author Ross Lawley <ross.lawley@gmail.com> * @since 0.11.0 */ public function autoload($className) { if (class_exists($className, false)) return true; $isModel = (substr($className, -5) == 'Model') ? true : false; if (!$isModel) return false; $modelName = substr($className, 0, -5); // Check if is a module model $moduleParts = explode("_", $modelName); $moduleName = array_shift($moduleParts); $moduleModelName = implode("_", $moduleParts); $file = AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/models/' . $moduleModelName . 'Model.class.php'; // If not a module model try a global model if(!is_readable($file)) { $file = AgaviConfig::get('core.model_dir') . '/' . $modelName . 'Model.class.php'; } // Require the file if(is_readable($file)) { require($file); return true; } return false; } /** * Execute the shutdown procedure. * * @throws <b>AgaviDatabaseException</b> If an error occurs while shutting * down this database. * * @author Sean Kerr <skerr@mojavi.org> * @since 0.9.0 */ public function shutdown() { // Do I need these?? spl_autoload_unregister(array('Doctrine', 'autoload')); spl_autoload_unregister(array($this, 'autoload')); return; } } ?>
This paste will be private.
From the Design Piracy series on my blog: