31 abstract public static function _affectsRelationObjects($className, $classPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, $objects, $included, $useCache): void;
33 abstract protected static function prepareManyToMany($db, &$ret, $instance, $member, $annot =
null);
35 abstract protected static function prepareManyToOne(&$ret, $instance, $value, $fkField, $annotationArray);
37 abstract protected static function prepareOneToMany(&$ret, $instance, $member, $annot =
null);
39 abstract public static function _initRelationFields($included, $metaDatas, &$invertedJoinColumns, &$oneToManyFields, &$manyToManyFields): void;
43 abstract protected static function getDb($model);
46 if (\is_object($instance)) {
47 return get_class($instance);
53 if (\is_object($instance)) {
59 protected static function getValue_($instance, $member) {
60 if (\is_object($instance)) {
61 return Reflexion::getMemberValue($instance, $member);
67 if (\is_object($instance)) {
76 $object = $invertedJoinColumns = $oneToManyFields = $manyToManyFields =
null;
79 $tableName = $metaDatas [
'#tableName'];
80 $hasIncluded = $included || (\is_array($included) && \count($included) > 0);
84 $transformers = $metaDatas [
'#transformers'] [self::$transformerOp] ?? [];
85 $query = $db->
prepareAndExecute($tableName, SqlUtils::checkWhere($conditionParser->
getCondition()), self::_getFieldList($tableName, $metaDatas), $conditionParser->
getParams(), $useCache,
true);
87 $oneToManyQueries = $manyToOneQueries = $manyToManyParsers = [];
88 $object =
self::_loadObjectFromRow($db, $query, $className, $invertedJoinColumns, $manyToOneQueries, $oneToManyFields, $manyToManyFields, $oneToManyQueries, $manyToManyParsers, $metaDatas [
'#memberNames'] ??
null, $metaDatas [
'#accessors'], $transformers, $metaDatas[
'#primaryKeys'] ?? []);
92 EventsManager::trigger(DAOEvents::GET_ONE, $object, $className);
109 $invertedJoinColumns = $oneToManyFields = $manyToManyFields =
null;
112 $primaryKeys = $metaDatas[
'#primaryKeys'] ?? [];
113 $tableName = $metaDatas [
'#tableName'];
114 if ($hasIncluded = ($included || (\is_array($included) && \count($included) > 0))) {
117 $transformers = $metaDatas [
'#transformers'] [self::$transformerOp] ?? [];
118 $query = $db->
prepareAndExecute($tableName, SqlUtils::checkWhere($conditionParser->
getCondition()), self::_getFieldList($tableName, $metaDatas), $conditionParser->
getParams(), $useCache);
120 $oneToManyQueries = $manyToOneQueries = $manyToManyParsers = [];
123 foreach ($query as $row) {
124 $object =
self::_loadObjectFromRow($db, $row, $className, $invertedJoinColumns, $manyToOneQueries, $oneToManyFields, $manyToManyFields, $oneToManyQueries, $manyToManyParsers, $metaDatas [
'#memberNames'] ??
null, $metaDatas [
'#accessors'], $transformers, $primaryKeys);
130 EventsManager::trigger(DAOEvents::GET_ALL, $objects, $className);
135 return self::$fields [$tableName] ??= SqlUtils::getFieldList(\array_diff($metaDatas [
'#fieldNames'], $metaDatas [
'#notSerializable']), $tableName);
154 public static function _loadObjectFromRow(
Database $db, $row, $className, $invertedJoinColumns, &$manyToOneQueries, $oneToManyFields, $manyToManyFields, &$oneToManyQueries, &$manyToManyParsers, $memberNames,
$accessors, $transformers, $primaryKeys) {
155 $o =
new $className ();
156 if (self::$useTransformers) {
159 foreach ($row as $k => $v) {
160 if ($accesseur = (
$accessors [$k] ??
false)) {
163 $o->_rest [$memberNames [$k] ?? $k] = $v;
164 if (isset($primaryKeys[$k])) {
165 $o->_pkv[
'___' . $k] = $v;
167 if (isset ($invertedJoinColumns) && isset ($invertedJoinColumns [$k])) {
173 self::loadManys($o, $db, $oneToManyFields, $oneToManyQueries, $manyToManyFields, $manyToManyParsers);
187 $o =
new $className ();
188 if (self::$useTransformers) {
191 foreach ($row as $k => $v) {
193 $o->_rest [$memberNames [$k] ?? $k] = $v;
199 foreach ($transformers as $member => $transformer) {
200 $field = \array_search($member, $memberNames);
201 $transform = self::$transformerOp;
202 $row [$field] = $transformer::{$transform} ($row [$field]);
206 protected static function loadManys($o, $db, $oneToManyFields, &$oneToManyQueries, $manyToManyFields, &$manyToManyParsers) {
207 if (isset ($oneToManyFields)) {
208 foreach ($oneToManyFields as $k => $annot) {
212 if (isset ($manyToManyFields)) {
213 foreach ($manyToManyFields as $k => $annot) {
219 private static function parseKey(&$keyValues, $className, $quote) {
220 if (!\is_array($keyValues)) {
221 if (\strrpos($keyValues,
'=') ===
false && \strrpos($keyValues,
'>') ===
false && \strrpos($keyValues,
'<') ===
false) {
228 $offset = self::$modelsDatabase [$model] ??
'default';
229 if (isset (self::$db [$offset])) {
230 self::$db [$offset]->storeCache();
234 public static function getModels($dbOffset =
'default') {
236 foreach (self::$modelsDatabase as $model => $offset) {
237 if ($offset === $dbOffset) {
Ubiquity Generic database class.
prepareAndExecute($tableName, $condition, $fields, $parameters=null, $useCache=false, $one=false)
Object/relational mapping utilities.
static getPropKeyValues($instance, $props)
static getFirstKeyValue($instance)
static getModelMetadata($className)
Represents a query condition.
Reflection utilities in dev environment only.
static _getIncludedForStep($included)
static prepareManyToOne(&$ret, $instance, $value, $fkField, $annotationArray)
static prepareOneToMany(&$ret, $instance, $member, $annot=null)
static _loadObjectFromRow(Database $db, $row, $className, $invertedJoinColumns, &$manyToOneQueries, $oneToManyFields, $manyToManyFields, &$oneToManyQueries, &$manyToManyParsers, $memberNames, $accessors, $transformers, $primaryKeys)
static prepareManyToMany($db, &$ret, $instance, $member, $annot=null)
static _getFieldList($tableName, $metaDatas)
static _initRelationFields($included, $metaDatas, &$invertedJoinColumns, &$oneToManyFields, &$manyToManyFields)
static getFirstKeyValue_($instance)
static _getOne(Database $db, $className, ConditionParser $conditionParser, $included, $useCache)
static getClass_($instance)
static getInstance_($instance)
static getValue_($instance, $member)
static getModels($dbOffset='default')
static _loadSimpleObjectFromRow(Database $db, $row, $className, $memberNames, $transformers)
static _getAll(Database $db, $className, ConditionParser $conditionParser, $included=true, $useCache=null)
static storeDbCache(string $model)
static loadManys($o, $db, $oneToManyFields, &$oneToManyQueries, $manyToManyFields, &$manyToManyParsers)
static parseKey(&$keyValues, $className, $quote)
static applyTransformers($transformers, &$row, $memberNames)
static _affectsRelationObjects($className, $classPropKey, $manyToOneQueries, $oneToManyQueries, $manyToManyParsers, $objects, $included, $useCache)
static getPropKeys($class)
static getFirstPropKey($class)
static getFirstKey($class)
Ubiquity\orm\traits This class is part of Ubiquity.