Commit 01ad0732 authored by Bertrand Gauthier's avatar Bertrand Gauthier
Browse files

Déplacement de certaines vérif de la config

parent 36fd289a
Pipeline #12338 passed with stage
in 16 seconds
......@@ -63,9 +63,6 @@ class DbfakatorService
*/
public function setConfig(array $config): self
{
Assert::keyExists($config, $k = 'entities', "La config du module doit posséder la clé '$k'");
Assert::keyExists($config, $k = 'output', "La config du module doit posséder la clé '$k'");
$this->entitiesConfig = $config['entities'];
$this->outputConfig = $config['output'];
......@@ -84,15 +81,11 @@ class DbfakatorService
public function getAnonymisationScriptPath()
{
Assert::keyExists($this->outputConfig, $k = 'anonymisation', "La config 'output' doit posséder la clé '$k'");
return $this->outputConfig['anonymisation'];
}
public function getRestaurationScriptPath()
{
Assert::keyExists($this->outputConfig, $k = 'restauration', "La config 'output' doit posséder la clé '$k'");
return $this->outputConfig['restauration'];
}
......
......@@ -15,16 +15,36 @@ class DbfakatorServiceFactory
*/
public function __invoke(ContainerInterface $container): DbfakatorService
{
/** @var array $config */
$config = $container->get('Config');
/** @var \Doctrine\ORM\EntityManager $em */
$em = $container->get('doctrine.entitymanager.orm_default');
$config = $this->getConfig($container);
$service = new DbfakatorService();
$service->setConfig($config['unicaen-dbfakator'] ?? []);
$service->setConfig($config);
$service->setEntityManager($em);
return $service;
}
/**
* @throws \Psr\Container\ContainerExceptionInterface
* @throws \Psr\Container\NotFoundExceptionInterface
*/
private function getConfig(ContainerInterface $container): array
{
/** @var array $appConfig */
$appConfig = $container->get('Config');
$config = $appConfig['unicaen-dbfakator'] ?? [];
if ($config) {
return [];
}
Assert::isArray($config, "La config du module doit être un tableau");
Assert::keyExists($config, $k = 'entities', "La config du module doit posséder la clé '$k'");
Assert::keyExists($config, $k = 'output', "La config du module doit posséder la clé '$k'");
return $config;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment