Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
DAOPreparedQueryById.php
Go to the documentation of this file.
1<?php
2
4
11
20
25 protected $cache;
26
27 public function __construct($className, $included = false, $cache = null) {
28 parent::__construct($className, '', $included, $cache);
29 }
30
31 protected function prepare(?DbCache $cache = null) {
32 parent::prepare($cache);
33 $keys = OrmUtils::getKeyFields($this->className);
34 $this->conditionParser->prepareKeys($keys);
35 $this->conditionParser->limitOne();
36 $this->cache = DAO::getCache();
38 }
39
40 public function execute($params = [], $useCache = false) {
41 if ($useCache && isset($this->cache) && ($object = $this->cache->fetch($this->className, \implode('_', $params)))) {
42 return $object;
43 }
44
45 $params = $this->conditionParser->setKeyValues($params);
46 if ($useCache) {
47 $row = $this->db->_optExecuteAndFetch($this->statement, $this->tableName, $this->preparedCondition, $params, $useCache, true);
48 } else {
49 $row = $this->db->_optExecuteAndFetchNoCache($this->statement, $params, true);
50 }
51 if ($row) {
53 if ($this->hasIncluded || !$this->allPublic) {
54 $oneToManyQueries = $manyToOneQueries = $manyToManyParsers = [];
55 $object = DAO::_loadObjectFromRow($this->db, $row, $className, $this->invertedJoinColumns, $manyToOneQueries, $this->oneToManyFields, $this->manyToManyFields, $oneToManyQueries, $manyToManyParsers, $this->memberList, $this->accessors, $this->transformers, $this->primaryKeys);
56 if ($this->hasIncluded) {
57 DAO::_affectsRelationObjects($className, $this->firstPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, [
58 $object
59 ], $this->included, $useCache);
60 }
61 } else {
62 $object = DAO::_loadSimpleObjectFromRow($this->db, $row, $className, $this->memberList, $this->transformers);
63 }
64 if ($this->additionalMembers) {
65 $this->addAditionnalMembers($object, $row);
66 }
67 EventsManager::trigger(DAOEvents::GET_ONE, $object, $className);
68 return $object;
69 }
70 return null;
71 }
72}
Ubiquity\cache\dao$AbstractDAOCache This class is part of Ubiquity.
Abstract class for database caching Ubiquity\cache\database$DbCache This class is part of Ubiquity.
Definition DbCache.php:20
DAO events constants.
Definition DAOEvents.php:14
Gateway class between database and object model.
Definition DAO.php:33
static getCache()
Definition DAO.php:379
Object/relational mapping utilities.
Definition OrmUtils.php:17
Ubiquity\orm\core\prepared$DAOPreparedQueryOne This class is part of Ubiquity.
__construct($className, $included=false, $cache=null)
Ubiquity\orm\core\prepared$DAOPreparedQuery This class is part of Ubiquity.
static _loadObjectFromRow(Database $db, $row, $className, $invertedJoinColumns, &$manyToOneQueries, $oneToManyFields, $manyToManyFields, &$oneToManyQueries, &$manyToManyParsers, $memberNames, $accessors, $transformers, $primaryKeys)
static _loadSimpleObjectFromRow(Database $db, $row, $className, $memberNames, $transformers)
static _affectsRelationObjects($className, $classPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, $objects, $included, $useCache)
static getKeyFields($instance)
Return primary key fields from instance or model class.