mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-07-01 14:36:13 +00:00
Add Doctrine extension.
This commit is contained in:
parent
b41b1346e5
commit
d208a79764
@ -32,9 +32,8 @@ use Chill\MainBundle\Doctrine\DQL\JsonAggregate;
|
|||||||
use Chill\MainBundle\Doctrine\DQL\JsonbExistsInArray;
|
use Chill\MainBundle\Doctrine\DQL\JsonbExistsInArray;
|
||||||
use Chill\MainBundle\Doctrine\DQL\Similarity;
|
use Chill\MainBundle\Doctrine\DQL\Similarity;
|
||||||
use Chill\MainBundle\Doctrine\DQL\OverlapsI;
|
use Chill\MainBundle\Doctrine\DQL\OverlapsI;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
|
||||||
use Chill\MainBundle\Doctrine\DQL\Replace;
|
use Chill\MainBundle\Doctrine\DQL\Replace;
|
||||||
|
use Chill\MainBundle\Doctrine\ORM\Hydration\FlatHierarchyEntityHydrator;
|
||||||
use Chill\MainBundle\Doctrine\Type\NativeDateIntervalType;
|
use Chill\MainBundle\Doctrine\Type\NativeDateIntervalType;
|
||||||
use Chill\MainBundle\Doctrine\Type\PointType;
|
use Chill\MainBundle\Doctrine\Type\PointType;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@ -186,6 +185,9 @@ class ChillMainExtension extends Extension implements PrependExtensionInterface,
|
|||||||
'OVERLAPSI' => OverlapsI::class,
|
'OVERLAPSI' => OverlapsI::class,
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
'hydrators' => [
|
||||||
|
'chill_flat_hierarchy_list' => FlatHierarchyEntityHydrator::class,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Chill\MainBundle\Doctrine\ORM\Hydration;
|
||||||
|
|
||||||
|
use Doctrine\ORM\Internal\Hydration\ObjectHydrator;
|
||||||
|
use Generator;
|
||||||
|
|
||||||
|
final class FlatHierarchyEntityHydrator extends ObjectHydrator
|
||||||
|
{
|
||||||
|
public const LIST = 'chill_flat_hierarchy_list';
|
||||||
|
|
||||||
|
protected function hydrateAllData(): array
|
||||||
|
{
|
||||||
|
$generator = $this->buildRecursively(
|
||||||
|
parent::hydrateAllData(),
|
||||||
|
static fn($value): iterable => $value->getChildren(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$result = [];
|
||||||
|
|
||||||
|
foreach ($generator as $entity) {
|
||||||
|
// We cannot expect anything from the object entity
|
||||||
|
// so, we cannot expect it to have a ::getId() method.
|
||||||
|
// So we use spl_object_hash() instead.
|
||||||
|
$result += [spl_object_hash($entity) => $entity];
|
||||||
|
}
|
||||||
|
|
||||||
|
return array_values($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param iterable<int, SocialIssue> $iterable
|
||||||
|
* @param callable(SocialIssue): iterable<int, SocialIssue> $childrenAccessor
|
||||||
|
*
|
||||||
|
* @return Generator<int, SocialIssue>
|
||||||
|
*/
|
||||||
|
private function buildRecursively(iterable $iterable, callable $childrenAccessor): Generator
|
||||||
|
{
|
||||||
|
foreach ($iterable as $item)
|
||||||
|
{
|
||||||
|
yield $item;
|
||||||
|
|
||||||
|
yield from $this->buildRecursively($childrenAccessor($item), $childrenAccessor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user