summaryrefslogtreecommitdiff
path: root/app/php/facades/Facade.php
blob: 346024acc6c087fafb7fb52eac175cf0945746a6 (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
61
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
        );
    }

}

?>