mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-10-04 20:39:40 +00:00
Add external identifiers for person, editable in edit form, with minimal features associated
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/*
|
||||
* Chill is a software for social workers
|
||||
*
|
||||
* For the full copyright and license information, please view
|
||||
* the LICENSE file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Chill\PersonBundle\PersonIdentifier;
|
||||
|
||||
use Chill\PersonBundle\Entity\Identifier\PersonIdentifierDefinition;
|
||||
use Chill\PersonBundle\PersonIdentifier\Exception\EngineNotFoundException;
|
||||
use Chill\PersonBundle\Repository\Identifier\PersonIdentifierDefinitionRepository;
|
||||
|
||||
final readonly class PersonIdentifierManager implements PersonIdentifierManagerInterface
|
||||
{
|
||||
public function __construct(
|
||||
private iterable $engines,
|
||||
private PersonIdentifierDefinitionRepository $personIdentifierDefinitionRepository,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Build PersonIdentifierWorker's for all active definition.
|
||||
*
|
||||
* @return list<PersonIdentifierWorker>
|
||||
*/
|
||||
public function getWorkers(): array
|
||||
{
|
||||
$workers = [];
|
||||
foreach ($this->personIdentifierDefinitionRepository->findByActive() as $definition) {
|
||||
try {
|
||||
$worker = $this->getEngine($definition->getEngine());
|
||||
} catch (EngineNotFoundException) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$workers[] = new PersonIdentifierWorker($worker, $definition);
|
||||
|
||||
}
|
||||
|
||||
return $workers;
|
||||
}
|
||||
|
||||
public function buildWorkerByPersonIdentifierDefinition(PersonIdentifierDefinition $personIdentifierDefinition): PersonIdentifierWorker
|
||||
{
|
||||
return new PersonIdentifierWorker($this->getEngine($personIdentifierDefinition->getEngine()), $personIdentifierDefinition);
|
||||
}
|
||||
|
||||
/**
|
||||
* @throw EngineNotFoundException
|
||||
*/
|
||||
private function getEngine(string $name): PersonIdentifierEngineInterface
|
||||
{
|
||||
foreach ($this->engines as $engine) {
|
||||
if ($engine->getName() === $name) {
|
||||
return $engine;
|
||||
}
|
||||
}
|
||||
|
||||
throw new EngineNotFoundException($name);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user