- WIP on reworking lean-api's visual

This commit is contained in:
Dave Mc Nicoll committed 2024-11-11 15:52:46 +00:00
1 parent d2202066ba
commit cb27ab7974
12 files changed
+92 -1

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
<?php
namespace Lean\Api\Attribute;
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_CLASS)]
class EntityField
{
public function __construct(
public string $description = "",
public bool $mandatory = false,
public ?int $minLength = null,
public ?int $maxLength = null,
public ?string $regexFormat = null,
public mixed $example = null,
) {}
}
+3 -1
View File
@@ -2,6 +2,7 @@
namespace Lean\Api;
use Lean\Api\Attribute\EntityField;
use Lean\Factory\HttpFactory;
use Notes\ObjectReflection;
use Notes\Route\Attribute\Method\Route;
@@ -80,6 +81,7 @@ class EntityDescriptor
$table = $reflector->reflectClass()->getAttribute(Table::class);
foreach($reflector->reflectProperties() as $property) {
$entityField = $property->getAttribute(EntityField::class);
$field = $property->getAttribute(Field::class);
if ($field) {
@@ -87,7 +89,7 @@ class EntityDescriptor
$propertyHtml .= sprintf(
$this->entityField,
$property->name,
$field->object->description,
$entityField->object->description ?? "",
$field->object->name ?: $property->name,
$field->tag,
$field->object->type ?? implode(' | ', array_map(fn($e) => $e->type, $types)),