/framework/core/db/DbModule.php
PHP | 69 lines | 37 code | 5 blank | 27 comment | 2 complexity | d8e3407620b5d9eb28fc5f766a46a297 MD5 | raw file
1<?php 2class DbModule extends ZoopModule 3{ 4 private static $connections = array(); 5 6 /** 7 * Returns a DbConnection object to the database called "$name" 8 * 9 * @param string $name 10 * @return DbConnection 11 */ 12 static function getConnection($name) 13 { 14 if(!isset(self::$connections[$name])) 15 trigger_error("connection '$name' does not exist"); 16 return self::$connections[$name]; 17 } 18 19 /** 20 * Returns a DbConnection object for the default database connection 21 * 22 * @return DbConnection 23 */ 24 static function getDefaultConnection() 25 { 26 return self::getConnection('default'); 27 } 28 29 /** 30 * This method is overridden to tell zoop which files to include with this module 31 * 32 * @return array of filenames to include 33 */ 34 function getIncludes() 35 { 36 return array('functions.php'); 37 } 38 39 /** 40 * This method is overridden to tell zoop which classes exist as part of this module 41 * so that they can be added to the autoloader 42 * 43 * @return unknown 44 */ 45 function getClasses() 46 { 47 return array('DbConnection', 'DbFactory', 'DbSchema', 'DbObject', 'DbZone', 'DbTable', 'DbField', 48 'DbPdo', 'DbPdoResult', 'DbPgsql', 'DbPgResult', 'DbMysql', 'DbMysqlResult', 49 'DbMssql', 'DbMssqlResult', 'DbResultSet', 'DbRelationshipBelongsTo', 'DbRelationshipBasic' 50 , 'DbRelationship', 'DbRelationshipHasMany', 'DbRelationshipHasOne', 'DbRelationshipOptions'); 51 } 52 53 /** 54 * This method reads the configuration options (using the getConfig method) 55 * and initializes the database connections. 56 * 57 */ 58 function configure() 59 { 60 $connections = $this->getConfig(); 61 if($connections) 62 { 63 foreach($connections as $name => $params) 64 { 65 self::$connections[$name] = DbFactory::getConnection($params, $name); 66 } 67 } 68 } 69}