mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-21 15:13:50 +00:00
generate context for evaluations
This commit is contained in:
@@ -29,4 +29,6 @@ interface DocGeneratorContextWithPublicFormInterface extends DocGeneratorContext
|
||||
* @param mixed $entity
|
||||
*/
|
||||
public function hasPublicForm(DocGeneratorTemplate $template, $entity): bool;
|
||||
|
||||
public function getFormData(DocGeneratorTemplate $template, $entity): array;
|
||||
}
|
||||
|
@@ -106,7 +106,7 @@ final class DocGeneratorTemplateController extends AbstractController
|
||||
|
||||
if ($context instanceof DocGeneratorContextWithPublicFormInterface
|
||||
&& $context->hasPublicForm($template, $entity)) {
|
||||
$builder = $this->createFormBuilder();
|
||||
$builder = $this->createFormBuilder($context->getFormData($template, $entity));
|
||||
$context->buildPublicForm($builder, $template, $entity);
|
||||
$form = $builder->getForm()->handleRequest($request);
|
||||
|
||||
|
@@ -99,6 +99,24 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
||||
}
|
||||
|
||||
$type = $reflection->getProperty($attribute->getName())->getType();
|
||||
} elseif ($reflection->hasMethod($method = 'get'.ucfirst($attribute->getName()))) {
|
||||
if (!$reflection->getMethod($method)->hasReturnType()) {
|
||||
throw new \LogicException(sprintf(
|
||||
'Could not determine how the content is determined for the attribute %s. Add a return type on the method',
|
||||
$attribute->getName()
|
||||
));
|
||||
}
|
||||
|
||||
$type = $reflection->getMethod($method)->getReturnType();
|
||||
} elseif ($reflection->hasMethod($method = 'is'.ucfirst($attribute->getName()))) {
|
||||
if (!$reflection->getMethod($method)->hasReturnType()) {
|
||||
throw new \LogicException(sprintf(
|
||||
'Could not determine how the content is determined for the attribute %s. Add a return type on the method',
|
||||
$attribute->getName()
|
||||
));
|
||||
}
|
||||
|
||||
$type = $reflection->getMethod($method)->getReturnType();
|
||||
} elseif ($reflection->hasMethod($attribute->getName())) {
|
||||
if (!$reflection->getMethod($attribute->getName())->hasReturnType()) {
|
||||
throw new \LogicException(sprintf(
|
||||
@@ -149,11 +167,13 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
||||
|
||||
switch ($type) {
|
||||
case 'array':
|
||||
return [];
|
||||
case 'bool':
|
||||
case 'double':
|
||||
case 'float':
|
||||
case 'int':
|
||||
case 'resource':
|
||||
return null;
|
||||
case 'string':
|
||||
return '';
|
||||
|
||||
@@ -197,7 +217,7 @@ class DocGenObjectNormalizer implements NormalizerAwareInterface, NormalizerInte
|
||||
} elseif (null === $value) {
|
||||
$data[$key] = $this->normalizeNullOutputValue($format, $context, $attribute, $reflection);
|
||||
} else {
|
||||
$data[$key] = (string) $value;
|
||||
$data[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user