adachsoft / principal-contact
Contact data of principals for any PHP application: contact service with access policy, e-mail and phone validators and an e-mail address resolver for adachsoft/notification-channel-email.
Requires
- php: ^8.3
- adachsoft/notification-channel-email: ^0.1
- adachsoft/principal-contact-contracts: ^0.1
- adachsoft/reference-contracts: ^0.1
- psr/clock: ^1.0
Requires (Dev)
- adachsoft/php-code-style: ^0.7.4
- friendsofphp/php-cs-fixer: ^3.95
- phpstan/phpstan: ^2.3
- phpunit/phpunit: ^13.4
- rector/rector: ^2.8
- symplify/phpstan-rules: ^14.19
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
adachsoft/principal-contact manages contact details for application principals such as users, accounts, or groups. It provides an access-controlled contact service, e-mail and phone validation, and an e-mail address resolver for notification integrations. Storage is supplied through a repository contract, so applications can choose an adapter.
Requirements and installation
- PHP 8.3 or newer
- Composer
composer require adachsoft/principal-contact
Usage
Create a repository and service, then use principal references from adachsoft/reference-contracts:
use AdachSoft\PrincipalContact\Service\ContactServiceFactory;
use AdachSoft\PrincipalContactContracts\InMemory\InMemoryPrincipalContactsRepository;
use AdachSoft\ReferenceContracts\PrincipalReference;
$repository = new InMemoryPrincipalContactsRepository();
$service = ContactServiceFactory::create($repository);
$principal = new PrincipalReference('account', 'account-42');
$contacts = $service->contactsOf($principal, $principal);
The factory defaults to self-only access, built-in e-mail and phone validators, and a system clock. Applications can provide a custom access policy, validator registry, change listener, or PSR-20 clock. replaceContacts() validates and normalizes values, supports optimistic version checks, and notifies an optional listener when contacts change.
See Basic usage for a complete example covering contact updates, access denial, normalization, versioning, and e-mail resolution.
Storage and notifications
The in-memory repository from adachsoft/principal-contact-contracts is suitable for tests and short-lived processes. For persistent JSON-file storage, install adachsoft/principal-contact-json-file and pass its repository implementation to the factory.
ContactEmailAddressResolver adapts the repository to adachsoft/notification-channel-email. The notification channel and a transport implementation can be integrated separately.