mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2026-03-13 17:37:45 +00:00
- Replaced `Subject|array` return types with `SubjectBag` in `SubjectConverterInterface` for more robust handling. - Updated `getSubjectsForEntity` to include an optional `$includeAssociated` parameter for finer control over associated subject resolution. - Refactored `AuditEvent` to differentiate `mainSubject` from associated subjects, improving clarity in audit logging. - Introduced database schema changes to add `main_subject` and `subjects` columns in the `chill_main_audit_trail` table. - Added `SubjectBag` class for grouped subject management and implemented deduplication logic. - Updated all converters and test cases to use the new `SubjectBag` approach, ensuring compatibility. - Improved event dispatching in controllers to utilize the updated `AuditEvent` structure and refined metadata handling.
51 lines
1.1 KiB
PHP
51 lines
1.1 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;
|
|
|
|
class Subject
|
|
{
|
|
public function __construct(
|
|
public string $type,
|
|
/**
|
|
* @var array<string, string|number|\Stringable>
|
|
*/
|
|
public array $identifiers,
|
|
) {}
|
|
|
|
public function asArray(): array
|
|
{
|
|
return [...$this->identifiers, 't' => $this->type];
|
|
}
|
|
|
|
public function isEqual(Subject $subject): bool
|
|
{
|
|
if ($subject->type !== $this->type) {
|
|
return false;
|
|
}
|
|
|
|
foreach ($this->identifiers as $k => $identifierValue) {
|
|
if (!array_key_exists($k, $subject->identifiers)) {
|
|
return false;
|
|
}
|
|
if ($subject->identifiers[$k] !== $identifierValue) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
if (count($this->identifiers) !== count($subject->identifiers)) {
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|