- Work done to clarify a bit every section, and a hugh code refractoring also was made to the code base.

This commit is contained in:
Dave Mc Nicoll committed 2024-11-11 19:54:22 +00:00
1 parent a98e46c343
commit 6b655bdc76
15 files changed
+260 -145

No files matched your search

+34 -81
View File
@@ -15,93 +15,42 @@ class EntityDescriptor
{
use DescriptorTrait;
public string $entityTitle = <<<HTML
<div style="margin-left:15px">
<h4 class='entity-name'>%s</h4>
<div class='description'>%s</div>
<hr style="margin-top:15px">
<h5>Champs</h5>
<ol class='fields'>%s</ol>
<hr style="margin-top:15px;">
<h4 class='request-name'>%s</h4>
<h5>Requêtes</h5>
<div class='description' style="margin-bottom:10px">%s</div>
<ol class='requests'>%s</ol>
</div>
HTML;
public string $entityField = <<<HTML
<li class="odd-even">
<div style="display:flex; justify-content: space-between">
<div><strong style="font-family:monospace">$%s</strong> <span style='margin-left:15px'>%s</span></div>
</div>
<div class="field-desc" style="margin-top:10px;;background:#fff;padding:5px;font-size:0.9em">
<div style="padding:5px"><u>Champ SQL</u> : %s</div>
<div style="padding:5px"><u>Attribut</u> : %s</div>
<div style="padding:5px"><u>Type</u> : %s</div>
<div style="padding:5px"><u>Nullable</u> %s</div>
<div style="padding:5px"><u>Taille</u> : %s</div>
<div style="padding:5px"><u>Lecture seule</u> : %s</div>
</div>
</li>
HTML;
public string $searchRequestField = <<<HTML
<li class="odd-even">
<div style="display:flex; justify-content: space-between">
<div><strong style="font-family:monospace">$%s</strong> <span style='margin-left:15px'>%s</span></div>
</div>
<div class="field-desc" style="margin-top:10px;;background:#fff;padding:5px;font-size:0.9em">
<div style="padding:5px"><u>Paramètre de requête (GET)</u> : %s</div>
<div style="padding:5px"><u>Attribut</u> : %s</div>
<div style="padding:5px"><u>Type</u> : %s</div>
<div style="padding:5px"><u>Nullable</u> : %s</div>
<div style="padding:5px"><u>Valeur par défault</u> : %s</div>
</div>
</li>
HTML;
public function __construct() {}
/**
* @return Returns HTML describing entity fields
*/
public function describe(...$entities) : string
public function getEntities(...$entities) : array
{
$html = "";
$list = [];
foreach($entities as $entity) {
$propertyHtml = $searchRequestHtml = "";
$fields = [];
$entityName = is_object($entity) ? $entity::class : $entity;
$reflector = new ObjectReflection($entityName);
$table = $reflector->reflectClass()->getAttribute(Table::class);
foreach($reflector->reflectProperties() as $property) {
foreach ($reflector->reflectProperties() as $property) {
$entityField = $property->getAttribute(EntityField::class);
$field = $property->getAttribute(Field::class);
if ($field) {
$types = $property->getTypes();
$propertyHtml .= sprintf(
$this->entityField,
$property->name,
$entityField->object->description ?? "",
$field->object->name ?: $property->name,
$field->tag,
$field->object->type ?? implode(' | ', array_map(fn($e) => $e->type, $types)),
$this->yesOrNo($property->allowsNull()),
$this->length($field->object->length ?? null),
$this->yesOrNo($field->object->readonly),
);
$fields[] = [
'name' => $property->name,
'description' => $entityField->object->description ?? "",
'fieldName' => $field->object->name ?: $property->name,
'tag' => $field->tag,
'type' => $field->object->type ?? implode(' | ', array_map(fn($e) => $e->type, $types)),
'allowNulls' => $property->allowsNull(),
'length' => $field->object->length ?? null,
'readonly' => $field->object->readonly,
];
}
}
$searchFields = [];
$searchRequestReflector = new ObjectReflection($entityName::searchRequest()::class);
$searchRequestParameter = $searchRequestReflector->reflectClass()->getAttribute(SearchRequestParameter::class);
foreach($searchRequestReflector->reflectProperties() as $property) {
@@ -110,23 +59,27 @@ class EntityDescriptor
if ($field) {
$types = $property->getTypes();
$searchRequestHtml .= sprintf(
$this->searchRequestField,
$property->name,
$field->object->description,
$field->object->parameter ? implode(', ', $field->object->getParameters()) : $property->name,
$field->tag,
implode(' | ', array_map(fn($e) => $e->type, $types)),
$this->yesOrNo($property->allowsNull()),
$this->displayValue($property->value ?? "<i>aucune</i>")
);
$searchFields[] = [
'name' => $property->name,
'description' => $field->object->description,
'parameter' => $field->object->parameter ? implode(', ', $field->object->getParameters()) : $property->name,
'tag' => $field->tag,
'type' => implode(' | ', array_map(fn($e) => $e->type, $types)),
'allowNulls' => $property->allowsNull(),
'default' => $this->displayValue($property->value ?? "")
];
}
}
$html .= sprintf($this->entityTitle, $reflector->reflectClass()->getClassName(), $table->object->description ?? null, $propertyHtml, $reflector->reflectClass()->getClassName() . "::searchRequest()", $searchRequestParameter->object->description ?? "", $searchRequestHtml);
$list[$entity] = [
'className' => $reflector->reflectClass()->getClassName(),
'description' => $table->object->description ?? null,
'fields' => $fields,
'searchRequestDescription' => $searchRequestParameter->object->description ?? "",
'searchRequestFields' => $searchFields,
];
}
return $html;
return $list;
}
}