diff --git a/src/Entity/Security/ApiActionLog.php b/src/Entity/Security/ApiActionLog.php index 4171d98..9086444 100644 --- a/src/Entity/Security/ApiActionLog.php +++ b/src/Entity/Security/ApiActionLog.php @@ -47,14 +47,9 @@ class ApiActionLog implements EntityInterface, \JsonSerializable #[Field(name: "created_at")] public \Ulmus\Entity\Field\Datetime $createdAt; - #[Relation("oneToOne", key: "user", foreignKey: "id")] + #[Relation("oneToOne", key: "userId", foreignKey: "id")] public UserInterface $userEntity; - public function getUser() : ? UserInterface - { - - } - public function getHash() : string { return md5(sprintf("%d:%s", $this->id, $this->objectType)); diff --git a/src/EntityDescriptor.php b/src/EntityDescriptor.php index 3a91b4c..9754e76 100644 --- a/src/EntityDescriptor.php +++ b/src/EntityDescriptor.php @@ -31,6 +31,7 @@ class EntityDescriptor $table = $reflector->reflectClass()->getAttribute(Table::class); foreach ($reflector->reflectProperties() as $property) { + $possibleValues = null; $entityField = $property->getAttribute(EntityField::class); $field = $property->getAttribute(Field::class); @@ -45,6 +46,12 @@ class EntityDescriptor $default = $field->object->attributes['default'] ?? null; } + foreach($types as $type) { + if (! $type->builtIn && enum_exists($type->type)) { + $possibleValues = array_map(fn($e) => $e->value, $type->type::cases()); + } + } + $fields[] = [ 'name' => $property->name, 'description' => $entityField->object->description ?? "", @@ -55,6 +62,7 @@ class EntityDescriptor 'length' => $field->object->length ?? null, 'readonly' => $field->object->readonly, 'default' => $default, + 'possibleValues' => $possibleValues, 'arrayOf' => $arrayOf ?? null, ]; } diff --git a/src/Middleware/ApiRenderer.php b/src/Middleware/ApiRenderer.php index 248b72f..338e722 100644 --- a/src/Middleware/ApiRenderer.php +++ b/src/Middleware/ApiRenderer.php @@ -50,10 +50,19 @@ class ApiRenderer implements MiddlewareInterface { # For now, we match only response having a 'data' field if ( (is_array($payload) || $payload instanceof \ArrayAccess) && isset($payload['data'])) { + $humanSize = fn($size) => @round($size / pow(1024, $i=floor(log($size,1024))),2) . ['b','kb','mb','gb',][$i]; + return HttpFactory::createJsonResponse([ 'status' => 'success', 'ts' => time(), - ] + $payload, 200); + ] + $payload + (getenv('DEBUG') ? [ + 'debug' => [ + 'elapsed_time' => round(1000 * (microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]), 2), + 'memory_usage' => $humanSize(memory_get_usage()), + 'memory_peak_usage' => $humanSize(memory_get_peak_usage()), + 'pid' => getmypid(), + ] + ] : []), 200); } } diff --git a/view/lean-api/entity_descriptor.phtml b/view/lean-api/entity_descriptor.phtml index fb9a37e..e3c0976 100644 --- a/view/lean-api/entity_descriptor.phtml +++ b/view/lean-api/entity_descriptor.phtml @@ -73,6 +73,10 @@ {% endif %}