- 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

+21 -50
View File
@@ -9,46 +9,15 @@ class FormDescriptor
{
use DescriptorTrait;
public string $formTitle = <<<HTML
<div style="margin-left:15px">
<h4 style="background:#e0ecf7" class='form-name'>%s</h4>
<div class='description'>%s</div>
<hr style="margin-top:15px">
<h5>Champs</h5>
<ol class='fields'>%s</ol>
</div>
HTML;
public string $formField = <<<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>Variable POST / champ JSON</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>Pattern regex</u> : %s</div>
<div style="padding:5px"><u>Taille min.</u> : %s</div>
<div style="padding:5px"><u>Taille max.</u> : %s</div>
<div style="padding:5px"><u>Exemple</u> : %s</div>
</div>
</li>
HTML;
/**
* @return Returns HTML describing given controller's routes
*/
public function describe(...$forms) : string
public function getForms(...$forms) : array
{
$html = "";
$list = [];
foreach($forms as $form) {
$fields = [];
$propertyHtml = "";
$entityName = is_object($form) ? $form::class : $form;
$reflector = new ObjectReflection($entityName);
$formName = is_object($form) ? $form::class : $form;
$reflector = new ObjectReflection($formName);
$context = $reflector->reflectClass()->getAttribute(ContextField::class);
@@ -57,24 +26,26 @@ class FormDescriptor
if ($field) {
$types = $property->getTypes();
$propertyHtml .= sprintf(
$this->formField,
$property->name,
$field->object->description,
$property->name,
$field->object->type ?? implode(' | ', array_map(fn($e) => $e->type, $types)),
$this->yesOrNo($property->allowsNull()),
$field->object->regexFormat ?? "aucun",
$field->object->minLength ?? "aucune",
$field->object->maxLength ?? "aucune",
$field->object->example
);
$fields[] = [
'name' => $property->name,
'description' => $field->object->description,
'type' => $field->object->type ?? implode(' | ', array_map(fn($e) => $e->type, $types)),
'allowNulls' => $property->allowsNull(),
'regexPattern' =>$field->object->regexFormat ?? "aucun",
'minLength' =>$field->object->minLength ?? "aucune",
'maxLength' =>$field->object->maxLength ?? "aucune",
'example' =>$field->object->example,
];
}
}
$html .= sprintf($this->formTitle, $reflector->reflectClass()->getClassName(), $context->object->description ?? null, $propertyHtml, );
$list[$formName] = [
'className' => $reflector->reflectClass()->getClassName(),
'description' => $context->object->description ?? null,
'fields' => $fields,
];
}
return $html;
return $list;
}
}