mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-18 11:48:06 +00:00
Add audit system core with event handling and subject conversion
- Implemented `AuditEvent` class to represent audit events. - Added `AuditEvent2Trail` for converting events to audit trails. - Introduced `Subject` and `SubjectConverterManager` for subject conversion. - Created contracts like `SubjectConverterInterface` and `AuditEvent2TrailInterface`. - Developed `AuditEventSubscriber` to persist audit events using `AuditTrailPersister`. - Included test classes for core audit services and components.
This commit is contained in:
46
src/Bundle/ChillMainBundle/Audit/SubjectConverterManager.php
Normal file
46
src/Bundle/ChillMainBundle/Audit/SubjectConverterManager.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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\MainBundle\Audit;
|
||||
|
||||
use Chill\MainBundle\Audit\Exception\ConvertSubjectException;
|
||||
|
||||
final readonly class SubjectConverterManager implements SubjectConverterManagerInterface
|
||||
{
|
||||
public function __construct(
|
||||
/**
|
||||
* @var iterable<SubjectConverterInterface>
|
||||
*/
|
||||
private iterable $converters,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return list<array>
|
||||
*
|
||||
* @throws ConvertSubjectException
|
||||
*/
|
||||
public function convertEntityToSubjects(mixed $subject): array
|
||||
{
|
||||
foreach ($this->converters as $converter) {
|
||||
if ($converter->supportsConvert($subject)) {
|
||||
$subjects = $converter->convert($subject);
|
||||
|
||||
if ($subjects instanceof Subject) {
|
||||
return [$subjects->asArray()];
|
||||
}
|
||||
|
||||
return array_map(static fn (Subject $subject) => $subject->asArray(), $subjects);
|
||||
}
|
||||
}
|
||||
|
||||
throw new ConvertSubjectException($subject);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user