diff --git a/src/ORM/AssociationsNormalizerTrait.php b/src/ORM/AssociationsNormalizerTrait.php new file mode 100644 index 00000000000..da12d4bf8c7 --- /dev/null +++ b/src/ORM/AssociationsNormalizerTrait.php @@ -0,0 +1,66 @@ + $options) { + $pointer =& $result; + + if (is_int($table)) { + $table = $options; + $options = []; + } + + if (!strpos($table, '.')) { + $result[$table] = $options; + continue; + } + + $path = explode('.', $table); + $table = array_pop($path); + $first = array_shift($path); + $pointer += [$first => []]; + $pointer =& $pointer[$first]; + $pointer += ['associated' => []]; + + foreach ($path as $t) { + $pointer += ['associated' => []]; + $pointer['associated'] += [$t => []]; + $pointer['associated'][$t] += ['associated' => []]; + $pointer =& $pointer['associated'][$t]; + } + + $pointer['associated'] += [$table => []]; + $pointer['associated'][$table] = $options + $pointer['associated'][$table]; + } + + return isset($result['associated']) ? $result['associated'] : $result; + } + +}