blob: 9602ced0252b19c71264f4d255d1626624339b31 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
<?php
/**
* DaoManager class file.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @link http://www.pradosoft.com/
* @copyright Copyright © 2005-2006 PradoSoft
* @license http://www.pradosoft.com/license/
* @version $Id: DaoManager.php 3189 2012-07-12 12:16:21Z ctrlaltca $
* @package Demos
*/
Prado::using('System.Data.SqlMap.TSqlMapConfig');
/**
* DaoManager class.
*
* A Registry for Dao and an implementation of that type.
*
* @author Wei Zhuo <weizhuo[at]gmail[dot]com>
* @version $Id: DaoManager.php 3189 2012-07-12 12:16:21Z ctrlaltca $
* @package Demos
* @since 3.1
*/
class DaoManager extends TSqlMapConfig
{
/**
* @var array registered list of dao
*/
private $_dao=array();
/**
* Initializes the module.
* This method is required by IModule and is invoked by application.
* It loads dao information from the module configuration.
* @param TXmlElement module configuration
*/
public function init($xml)
{
parent::init($xml);
foreach($xml->getElementsByTagName("dao") as $node)
{
$this->_dao[$node->getAttribute('id')] =
array('class' => $node->getAttribute('class'));
}
}
/**
* @return array list of registered Daos
*/
public function getDaos()
{
return $this->_dao;
}
/**
* Returns an implementation of a Dao type, implements the Registery
* pattern. Multiple calls returns the same Dao instance.
* @param string Dao type to find.
* @return object instance of the Dao implementation.
*/
public function getDao($class)
{
if(isset($this->_dao[$class]))
{
if(!isset($this->_dao[$class]['instance']))
{
$dao = Prado::createComponent($this->_dao[$class]['class']);
$dao->setSqlMap($this->getClient());
$this->_dao[$class]['instance'] = $dao;
}
return $this->_dao[$class]['instance'];
}
else
throw new TimeTrackerException('daomanager_undefined_dao', $class);
}
}
|