PageRenderTime 90ms CodeModel.GetById 29ms RepoModel.GetById 16ms app.codeStats 0ms

/framework/core/db/DbModule.php

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