2026-08-24 21:06:11 +03:00
|
|
|
<?php
|
|
|
|
|
|
2026-09-16 01:21:22 +03:00
|
|
|
namespace Modules\Core\Privacy\Services;
|
2026-08-24 21:06:11 +03:00
|
|
|
|
2026-09-16 00:24:18 +03:00
|
|
|
use LogicException;
|
2026-08-24 21:06:11 +03:00
|
|
|
use Illuminate\Contracts\Container\Container;
|
|
|
|
|
use Modules\Core\Privacy\Contracts\PersonalDataProvider;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The registry every PersonalDataProvider is collected through. A module registers
|
|
|
|
|
* by adding its provider's class name to config('core.privacy.providers') — the
|
|
|
|
|
* same shape as Lunar's own config('lunar.search.indexers') model->indexer map, just
|
|
|
|
|
* a plain list since a provider isn't keyed to one model. Core never references a
|
|
|
|
|
* specific provider class; a future ERP/banking/etc. module just adds its own
|
|
|
|
|
* provider class to that config array and PrivacyService picks it up automatically.
|
|
|
|
|
*/
|
|
|
|
|
class PrivacyManager
|
|
|
|
|
{
|
|
|
|
|
public function __construct(private readonly Container $container) {}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array<int, PersonalDataProvider>
|
|
|
|
|
*/
|
|
|
|
|
public function providers(): array
|
|
|
|
|
{
|
|
|
|
|
$providers = array_map(
|
|
|
|
|
fn (string $class) => $this->container->make($class),
|
|
|
|
|
config('core.privacy.providers', [])
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$this->assertUniqueNames($providers);
|
|
|
|
|
|
|
|
|
|
return $providers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array<int, PersonalDataProvider> $providers
|
|
|
|
|
*/
|
|
|
|
|
private function assertUniqueNames(array $providers): void
|
|
|
|
|
{
|
|
|
|
|
$names = array_map(fn (PersonalDataProvider $provider) => $provider->name(), $providers);
|
|
|
|
|
$duplicates = array_diff_assoc($names, array_unique($names));
|
|
|
|
|
|
|
|
|
|
if ($duplicates !== []) {
|
2026-09-16 00:24:18 +03:00
|
|
|
throw new LogicException(
|
2026-08-24 21:06:11 +03:00
|
|
|
'Duplicate Modules\Core\Privacy provider name(s): '.implode(', ', array_unique($duplicates))
|
|
|
|
|
.'. Each provider registered in config(\'core.privacy.providers\') must return a unique name().'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|