|
1
|
|
|
<?php |
|
2
|
|
|
namespace Ubiquity\orm\traits; |
|
3
|
|
|
|
|
4
|
|
|
use Ubiquity\orm\core\prepared\DAOPreparedQueryOne; |
|
5
|
|
|
use Ubiquity\orm\core\prepared\DAOPreparedQueryById; |
|
6
|
|
|
use Ubiquity\orm\core\prepared\DAOPreparedQueryAll; |
|
7
|
|
|
use Ubiquity\orm\core\prepared\DAOPreparedQuery; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Ubiquity\orm\traits$DAOPreparedTrait |
|
11
|
|
|
* This class is part of Ubiquity |
|
12
|
|
|
* |
|
13
|
|
|
* @author jcheron <[email protected]> |
|
14
|
|
|
* @version 1.0.0 |
|
15
|
|
|
* |
|
16
|
|
|
*/ |
|
17
|
|
|
trait DAOPreparedTrait { |
|
18
|
|
|
|
|
19
|
|
|
protected static $preparedDAOQueries = []; |
|
20
|
|
|
|
|
21
|
28 |
|
public static function prepareGetById($name, $className, $included = false, $cache = null) { |
|
22
|
28 |
|
return self::$preparedDAOQueries[$name] = new DAOPreparedQueryById($className, $included, $cache); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
28 |
|
public static function prepareGetOne($name, $className, $condition = '', $included = false, $cache = null) { |
|
26
|
28 |
|
return self::$preparedDAOQueries[$name] = new DAOPreparedQueryOne($className, $condition, $included, $cache); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
28 |
|
public static function prepareGetAll($name, $className, $condition = '', $included = false, $cache = null) { |
|
30
|
28 |
|
return self::$preparedDAOQueries[$name] = new DAOPreparedQueryAll($className, $condition, $included, $cache); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
1 |
|
public static function executePrepared($name, $params = [], $useCache = false) { |
|
34
|
1 |
|
if (isset(self::$preparedDAOQueries[$name])) { |
|
35
|
1 |
|
return self::$preparedDAOQueries[$name]->execute($params, $useCache); |
|
36
|
|
|
} |
|
37
|
|
|
return null; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public static function storeDbCachePrepared($name) { |
|
41
|
|
|
if (isset(self::$preparedDAOQueries[$name])) { |
|
42
|
|
|
self::$preparedDAOQueries[$name]->storeDbCache(); |
|
43
|
|
|
} |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Returns the daoPreparedQuery corresponding to a name |
|
48
|
|
|
* |
|
49
|
|
|
* @param string $name |
|
50
|
|
|
* @return DAOPreparedQuery |
|
51
|
|
|
*/ |
|
52
|
1 |
|
public static function getPrepared(string $name): DAOPreparedQuery { |
|
53
|
1 |
|
return self::$preparedDAOQueries[$name]; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
|