summaryrefslogtreecommitdiff
path: root/app/frontend/facades/Facade.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/frontend/facades/Facade.php')
-rw-r--r--app/frontend/facades/Facade.php62
1 files changed, 62 insertions, 0 deletions
diff --git a/app/frontend/facades/Facade.php b/app/frontend/facades/Facade.php
new file mode 100644
index 0000000..346024a
--- /dev/null
+++ b/app/frontend/facades/Facade.php
@@ -0,0 +1,62 @@
+<?php
+
+Prado::using('System.Data.SqlMap.TSqlMapGateway');
+
+class Facade {
+
+ protected static $_instances = [];
+
+ protected $_sqlMap;
+
+ protected function __construct() {
+ }
+
+ public function __sleep() {
+ $this->_sqlMap = NULL;
+ return array();
+ }
+
+ public static function getInstance() {
+ $className = get_called_class();
+ if (!isset(static::$_instances[$className])) {
+ static::$_instances[$className] = new static();
+ }
+ return static::$_instances[$className];
+ }
+
+ protected function getClient() {
+ if (!$this->_sqlMap) {
+ $this->_sqlMap = Prado::getApplication()->getModule('sqlmap')->Client;
+ }
+ return $this->_sqlMap;
+ }
+
+ protected function quoteString($string) {
+ return $this->getClient()->DbConnection->quoteString($string);
+ }
+
+ protected function fetch($sqlMap, $params) {
+ return $this->getClient()->queryForObject($sqlMap, $params);
+ }
+
+ protected function fetchList($sqlMap, $params) {
+ return $this->getClient()->queryForList($sqlMap, $params);
+ }
+
+ protected function fetchMap($sqlMap, $params, $key, $value=NULL) {
+ return $this->getClient()->queryForMap($sqlMap, $params, $key, $value);
+ }
+
+ protected function beginTransaction() {
+ return $this->getClient()->DbConnection->beginTransaction();
+ }
+
+ protected function raiseEvent($event, ...$params) {
+ return Prado::getApplication()->getModule('events')->raiseApplicationEvent(
+ $event, ...$params
+ );
+ }
+
+}
+
+?>