mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-16 19:07:48 +00:00
- Added `AuditEventDumper` class to generate and store CSV exports of audit events based on search criteria. - Updated `SubjectDisplayerInterface` and related classes to support multiple output formats (`html` or `string`) for subject rendering.
57 lines
1.6 KiB
PHP
57 lines
1.6 KiB
PHP
<?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;
|
|
use Chill\MainBundle\Audit\Exception\DisplaySubjectException;
|
|
|
|
final readonly class SubjectConverterManager implements SubjectConverterManagerInterface
|
|
{
|
|
public function __construct(
|
|
/**
|
|
* @var iterable<SubjectConverterInterface>
|
|
*/
|
|
private iterable $converters,
|
|
|
|
/**
|
|
* @var iterable<SubjectDisplayerInterface>
|
|
*/
|
|
private iterable $displayers,
|
|
) {}
|
|
|
|
public function getSubjectsForEntity(mixed $subject, bool $includeAssociated = false): SubjectBag
|
|
{
|
|
foreach ($this->converters as $converter) {
|
|
if ($converter instanceof SubjectConverterManagerAwareInterface) {
|
|
$converter->setSubjectConverterManager($this);
|
|
}
|
|
|
|
if ($converter->supportsConvert($subject)) {
|
|
return $converter->convert($subject, $includeAssociated);
|
|
}
|
|
}
|
|
|
|
throw new ConvertSubjectException($subject);
|
|
}
|
|
|
|
public function display(Subject $subject, string $format = 'html', array $options = []): string
|
|
{
|
|
foreach ($this->displayers as $displayer) {
|
|
if ($displayer->supportsDisplay($subject)) {
|
|
return $displayer->display($subject, $format, $options);
|
|
}
|
|
}
|
|
|
|
throw new DisplaySubjectException($subject->asArray());
|
|
}
|
|
}
|