Open Journal Systems  2.4.4
 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  function &getDAOs() {
29  $daos =& Registry::get('daos', true, array());
30  return $daos;
31  }
32 
40  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  function &getDAO($name, $dbconn = null) {
58  $daos =& DAORegistry::getDAOs();
59 
60  if (!isset($daos[$name])) {
61  // Import the required DAO class.
62  $application =& PKPApplication::getApplication();
63  $className = $application->getQualifiedDAOName($name);
64  if (!$className) {
65  fatalError('Unrecognized DAO ' . $name . '!');
66  }
67 
68  // Only instantiate each class of DAO a single time
69  $daos[$name] =& instantiate($className, array('DAO', 'XMLDAO'));
70  if ($dbconn != null) {
71  $daos[$name]->setDataSource($dbconn);
72  }
73  }
74 
75  return $daos[$name];
76  }
77 }
78 
79 ?>
Maintains a static list of DAO objects so each DAO is instantiated only once.
& getDAO($name, $dbconn=null)
& get($key, $createIfEmpty=false, $createWithDefault=null)
& registerDAO($name, &$dao)