forked from fa/breadcrumb-the-shire
Migrates addressbook service classes from core namespace (MintyPHP\Service\AddressBook\*) to proper module namespace (MintyPHP\Module\AddressBook\Service\*), consistent with the bookmarks module pattern. Moved to module: - AddressBookService → modules/addressbook/lib/Module/AddressBook/Service/ - AddressBookServicesFactory → modules/addressbook/lib/Module/AddressBook/Service/ - AddressBookServiceTest → modules/addressbook/tests/Module/AddressBook/Service/ - Pages, templates, CSS, JS all in module directory All module PHP classes now live under MintyPHP\Module\<Name>\*, enforced by ModuleStructureContractTest::testModuleClassesUseModuleNamespace. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
41 lines
1.2 KiB
PHP
41 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace MintyPHP\Module\AddressBook\Providers;
|
|
|
|
use MintyPHP\App\AppContainer;
|
|
use MintyPHP\App\Module\Contracts\SessionProvider;
|
|
use MintyPHP\Http\SessionStoreInterface;
|
|
use MintyPHP\Service\User\UserTenantContextService;
|
|
|
|
/**
|
|
* Populates session with department-by-tenant hierarchy data used by the
|
|
* address book aside panel.
|
|
*/
|
|
final class AddressBookSessionProvider implements SessionProvider
|
|
{
|
|
public function populate(array $user, AppContainer $container): void
|
|
{
|
|
$userId = (int) ($user['id'] ?? 0);
|
|
if ($userId <= 0) {
|
|
unset($_SESSION['available_departments_by_tenant']);
|
|
return;
|
|
}
|
|
|
|
$tenantContext = $container->get(UserTenantContextService::class);
|
|
$sessionStore = $container->get(SessionStoreInterface::class);
|
|
if (!$tenantContext instanceof UserTenantContextService || !$sessionStore instanceof SessionStoreInterface) {
|
|
return;
|
|
}
|
|
|
|
$sessionStore->set(
|
|
'available_departments_by_tenant',
|
|
$tenantContext->getAvailableDepartmentsByTenant($userId)
|
|
);
|
|
}
|
|
|
|
public function clear(): void
|
|
{
|
|
unset($_SESSION['available_departments_by_tenant']);
|
|
}
|
|
}
|