[crud] clean and add documentation

This commit is contained in:
2020-03-12 22:31:21 +01:00
parent ad3ced9683
commit 13e81b3b49
5 changed files with 465 additions and 150 deletions

View File

@@ -69,29 +69,6 @@ class Resolver
foreach($crudConfig as $conf) {
$this->crudConfig[$conf['name']] = $conf;
}
$this->buildPropertyAccess();
}
private function buildPropertyAccess()
{
$this->propertyAccess = PropertyAccess::createPropertyAccessorBuilder()
->enableExceptionOnInvalidIndex()
->getPropertyAccessor();
}
/**
* Return the data at given path.
*
* Path are given to
*
* @param object $entity
* @param string $path
*/
public function getData($entity, $path)
{
return $this->propertyAccess->getValue($entity, $path);
}
public function getConfigValue($key, $crudName, $action = null)
@@ -116,43 +93,4 @@ class Resolver
'_'.
$action);
}
public function getTwigTemplate($entity, $path): string
{
list($focusEntity, $subPath) = $this->getFocusedEntity($entity, $path);
$classMetadata = $this->em->getClassMetadata(\get_class($focusEntity));
$type = $classMetadata->getTypeOfField($subPath);
switch ($type) {
default:
return '@ChillMain/CRUD/_inc/default.html.twig';
}
}
/**
* Get the object on which the path apply
*
* This methods recursively parse the path and entity and return the entity
* which will deliver the info, and the last path.
*
* @param object $entity
* @param string $path
* @return array [$focusedEntity, $lastPath]
*/
private function getFocusedEntity($entity, $path)
{
if (\strpos($path, '.') === FALSE) {
return [$entity, $path];
}
$exploded = \explode('.', $path);
$subEntity = $this->propertyAccess
->getValue($entity, $exploded[0]);
return $this->getFocusedEntity($subEntity,
\implode('.', \array_slice($exploded, 1)));
}
}