summaryrefslogtreecommitdiff
path: root/framework/DataAccess/SQLMap/TMapper.php
diff options
context:
space:
mode:
authorwei <>2006-04-14 06:22:09 +0000
committerwei <>2006-04-14 06:22:09 +0000
commit3d3f8d3832921f99daf8ce1953304763c2e76c62 (patch)
treee1b0a9bc3a13fccd253770fb452ac96cc6315121 /framework/DataAccess/SQLMap/TMapper.php
parent373d8acc503b94ea09823f49e2ab5e395eccc584 (diff)
Importing SQLMap + sample + docs.
Diffstat (limited to 'framework/DataAccess/SQLMap/TMapper.php')
-rw-r--r--framework/DataAccess/SQLMap/TMapper.php60
1 files changed, 60 insertions, 0 deletions
diff --git a/framework/DataAccess/SQLMap/TMapper.php b/framework/DataAccess/SQLMap/TMapper.php
new file mode 100644
index 00000000..4427c012
--- /dev/null
+++ b/framework/DataAccess/SQLMap/TMapper.php
@@ -0,0 +1,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;
+ }
+}
+
+?> \ No newline at end of file