Config Variables - Improve config variable system and initialize variables during setup.

This commit is contained in:
2024-12-12 15:38:28 +01:00
parent 28afb11ac4
commit dcd0b5f064
10 changed files with 175 additions and 58 deletions
+28 -3
View File
@@ -5,6 +5,7 @@ namespace App\Repository;
use App\Entity\ConfigVariable;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
use Ds\Set;
/**
* @extends ServiceEntityRepository<ConfigVariable>
@@ -51,14 +52,24 @@ class ConfigVariableRepository extends ServiceEntityRepository
* @param string Variable Key
* @return ConfigVariable|null Config Variable.
*/
public function findVariableByKey($varKey)
public function findVariableByKey($varKey): ConfigVariable|null
{
return $this->createQueryBuilder('c')
$rs = $this->createQueryBuilder('c')
->select('c.key, c.value, c.section')
->andWhere('c.key = :val')
->setParameter('val', $varKey)
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
->getResult();
// FIXME!!!
if (!$rs) {
return null;
}
$var = new ConfigVariable();
$var->setKey($rs[0]["key"]);
$var->setValue($rs[0]["value"]);
$var->setSection($rs[0]["section"]);
return $var;
}
/**
@@ -73,4 +84,18 @@ class ConfigVariableRepository extends ServiceEntityRepository
->getQuery()
->getResult();
}
/**
* Get all DB config variables names on a Set.
* @return Set Returns a Set with all variable names.
*/
public function getVariableSet(): Set
{
$varList = $this->findAll();
$keyList = array_map(function ($var) {
return $var->getKey();
}, $varList);
return new Set($keyList);
}
}