Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
DAORegistry.inc.php
1 <?php
2 
18 import('lib.pkp.classes.db.DAO');
19 
20 class DAORegistry {
21 
28  static function &getDAOs() {
29  $daos =& Registry::get('daos', true, array());
30  return $daos;
31  }
32 
40  static function registerDAO($name, $dao) {
41  $daos =& DAORegistry::getDAOs();
42  if (isset($daos[$name])) {
43  $returner = $daos[$name];
44  } else {
45  $returner = null;
46  }
47  $daos[$name] = $dao;
48  return $returner;
49  }
50 
57  static function &getDAO($name, $dbconn = null) {
58  $daos =& DAORegistry::getDAOs();
59  if (!isset($daos[$name])) {
60  // Import the required DAO class.
61  $application = PKPApplication::getApplication();
62  $className = $application->getQualifiedDAOName($name);
63  if (!$className) {
64  fatalError('Unrecognized DAO ' . $name . '!');
65  }
66 
67  // Only instantiate each class of DAO a single time
68  $daos[$name] =& instantiate($className, array('DAO', 'XMLDAO'));
69  if ($dbconn != null) {
70  $daos[$name]->setDataSource($dbconn);
71  }
72  }
73 
74  return $daos[$name];
75  }
76 }
77 
78 ?>
static & getDAO($name, $dbconn=null)
Maintains a static list of DAO objects so each DAO is instantiated only once.
static registerDAO($name, $dao)
static & getDAOs()
static & get($key, $createIfEmpty=false, $createWithDefault=null)