. */ namespace App\Services\LabelSystem; use App\Entity\LabelSystem\LabelProfile; use App\Repository\LabelProfileRepository; use App\Services\UserCacheKeyGenerator; use Doctrine\ORM\EntityManagerInterface; use Symfony\Contracts\Cache\ItemInterface; use Symfony\Contracts\Cache\TagAwareCacheInterface; class LabelProfileDropdownHelper { private $cache; private $entityManager; private $keyGenerator; public function __construct(TagAwareCacheInterface $treeCache, EntityManagerInterface $entityManager, UserCacheKeyGenerator $keyGenerator) { $this->cache = $treeCache; $this->entityManager = $entityManager; $this->keyGenerator = $keyGenerator; } public function getDropdownProfiles(string $type): array { $secure_class_name = str_replace('\\', '_', LabelProfile::class); $key = 'profile_dropdown_'.$this->keyGenerator->generateKey().'_'.$secure_class_name . '_' . $type; /** @var LabelProfileRepository $repo */ $repo = $this->entityManager->getRepository(LabelProfile::class); return $this->cache->get($key, function (ItemInterface $item) use ($repo, $type, $secure_class_name) { // Invalidate when groups, a element with the class or the user changes $item->tag(['groups', 'tree_treeview', $this->keyGenerator->generateKey(), $secure_class_name]); return $repo->getDropdownProfiles($type); }); } }