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