summaryrefslogtreecommitdiff
path: root/framework/DataAccess/SQLMap/TMapper.php
blob: 4427c0120204978f13d1032b26b7b9024d3c813f (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
<?php

require_once(dirname(__FILE__).'/TSqlMapClient.php');

/**
 * A singleton class to access the default SqlMapper.
 *
 * Usage: Call configure() once, then use instance() to obtain a TSqlMapper
 * instance. 
 * <code>  
 * TMapper::configure($configFile); 
 * $object = TMapper::instance()->queryForObject('statementName');
 * </code>
 * 
 * If your configuration file is named 'sqlmap.config' you may skip the
 * configure() call.
 *
 * @author Wei Zhuo <weizhuo[at]gmail[dot]com>
 * @version $Revision: $  $Date: $
 * @package System.DataAccess.SQLMap
 * @since 3.0
 */
class TMapper
{
	/**
	 * Data mapper singleton
	 * @var TSqlMapper
	 */
	private static $_mapper;

	/**
	 * Configure the data mapper singleton instance. 
	 * @param string configuration file
	 * @param boolean true to load configuration from cache.
	 * @return TSqlMapper data mapper instance.
	 */
	public static function configure($configFile,$loadCachedConfig=false)
	{
		if(is_null(self::$_mapper))
		{
			$sqlmap = new TSQLMapClient;
			self::$_mapper = $sqlmap->configure($configFile,$loadCachedConfig);
		}
		return self::$_mapper;
	}

	/**
	 * Gets the data mapper singleton instance. Default configuration file is
	 * 'sqlmap.config'.
	 * @return TSqlMapper singleton instance.
	 */
	public static function instance()
	{
		if(is_null(self::$_mapper))
			self::configure('sqlmap.xml');
		return self::$_mapper;
	}
}

?>