summaryrefslogtreecommitdiff
path: root/framework/DataAccess/SQLMap/TMapper.php
blob: 678306a6895f2e51342085abcd1cfe14253ffa11 (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 $Id$
 * @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;
	}
}

?>