Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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