22 return self::$modelsMetadatas [$className] ??= CacheManager::getOrmModelCache($className);
26 return !
self::_is($class, $member,
'#notSerializable');
30 return self::_is($class, $member,
'#nullable');
33 protected static function _is($class, $member, $like) {
36 return \array_search($member, $ret) !==
false;
42 return (self::getAnnotationInfo($class,
'#fieldNames') [$member]) ?? $member;
50 $class = \get_class($instance);
57 foreach ($members as $member) {
58 $v = Reflexion::getMemberValue($instance, $member);
59 $ret [$prefix . ($fieldnames [$member] ?? $member)] = $v;
66 foreach ($props as $prop) {
67 $v = Reflexion::getPropValue($instance, $prop);
68 $ret [$prop->getName()] = $v;
87 $className = \get_class($instance);
88 if (\is_null($members))
90 foreach ($members as $member) {
91 if (self::isSerializable($className, $member)) {
92 $v = Reflexion::getMemberValue($instance, $member);
93 if (self::isNotNullOrNullAccepted($v, $className, $member)) {
103 $notNull = (isset ($v) &&
null !== $v &&
'' !== $v);
109 return $prop->getValue($instance);
113 return \current(self::getFieldsAndValues_($instance, $members));
118 return \implode(
'_', $fkv);
123 foreach ($props as $prop) {
124 $values [] = $prop->getValue($instance);
126 return \implode(
'_', $values);
130 return (self::getModelMetadata($class) [$annotation]) ?? [];
140 public static function exists($instance, $memberKey, $array) {
141 $accessor =
'get' . \ucfirst($memberKey);
142 if (\method_exists($instance, $accessor)) {
143 foreach ($array as $value) {
144 if ($value->$accessor () == $instance->$accessor ())
157 if ($info !==
false) {
158 if (!isset ($info [0])) {
159 if (isset ($info [$member])) {
160 return $info [$member];
163 if (\array_search($member, $info) !==
false) {
172 foreach ($fields as $index => $field) {
173 if (isset ($relFields [$field])) {
174 $fields [$index] = $relFields [$field];
181 $datas = $formatter->cleanRestObject($instance);
182 return $formatter->format([
'pk' => self::getFirstKeyValue($instance),
'object' => $datas]);
186 if (isset (self::getModelMetadata($class) [
'#transformers']))
191 if (isset (self::getModelMetadata($class) [
'#accessors']))
196 self::$modelsMetadatas = [];
201 foreach ($members as $memberName) {
202 $field = new \ReflectionProperty ($className, $memberName);
203 if (!$field->isPublic()) {
Manager for caches (Router, Rest, models).
Object/relational mapping utilities.
static getAnnotationInfo($class, $keyAnnotation)
static getMembers($className)
static isSerializable($class, $member)
static getFirstKeyValue_($instance, $members)
static getTableName($class)
static getKeyPropsAndValues_($instance, $props)
static hasAllMembersPublic($className)
static getKeyValues($instance)
static getAccessors($class)
static isNotNullOrNullAccepted($v, $className, $member)
static exists($instance, $memberKey, $array)
static getPropKeyValues($instance, $props)
static getTransformers($class)
static objectAsJSON($instance)
static getPrimaryKeys($className)
static setFieldToMemberNames(&$fields, $relFields)
static getFieldName($class, $member)
static getKeyFieldsAndValues($instance, $prefix='')
static getFieldsAndValues_($instance, $members, $prefix='')
static getFirstKeyValue($instance)
static getModelMetadata($className)
static getMembersWithAnnotation($class, $annotation)
static isNullable($class, $member)
static getMembersAndValues($instance, $members=null)
static _is($class, $member, $like)
static getAnnotationInfoMember($class, $keyAnnotation, $member)
Reflection utilities in dev environment only.
Ubiquity\orm\traits$OrmUtilsFieldsTrait This class is part of Ubiquity.
static getFirstPropKey($class)