The Maatify\Verification module is designed to be easily injected into any PHP application using a PSR-11 compliant Dependency Injection (DI) container. The Bootstrap layer provides a standardized way to register all necessary interface-to-implementation mappings.
The primary entry point for integration is the VerificationBindings static class located in the Maatify\Verification\Bootstrap namespace.
use DI\ContainerBuilder;
use Maatify\Verification\Bootstrap\VerificationBindings;
$builder = new ContainerBuilder();
VerificationBindings::register($builder);
$container = $builder->build();The register() method configures the following mappings:
-
Repository: Binds
VerificationCodeRepositoryInterfacetoPdoVerificationCodeRepository.- Requirement: The container must already have a configured
PDOinstance and aMaatify\SharedCommon\Contracts\ClockInterfaceinstance available.
- Requirement: The container must already have a configured
-
Policy Resolver: Binds
VerificationCodePolicyResolverInterfaceto the defaultVerificationCodePolicyResolver. -
Generator: Binds
VerificationCodeGeneratorInterfacetoVerificationCodeGenerator.- It automatically injects the resolved Repository, Policy Resolver, and Clock.
-
Validator: Binds
VerificationCodeValidatorInterfacetoVerificationCodeValidator.- It automatically injects the resolved Repository and Clock.
Before calling VerificationBindings::register($builder), your application must ensure that the following dependencies are available in the DI container:
PDO: A configured connection to your database (if using the defaultPdoVerificationCodeRepository).Maatify\SharedCommon\Contracts\ClockInterface: An implementation of the clock contract (e.g.,Maatify\SharedCommon\SystemClock).
// Application-level DI configuration (e.g., in your framework's bootstrap)
$builder->addDefinitions([
PDO::class => function () {
return new PDO(
'mysql:host=localhost;dbname=test',
'user',
'pass',
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
},
\Maatify\SharedCommon\Contracts\ClockInterface::class => \DI\get(\Maatify\SharedCommon\SystemClock::class),
]);The VerificationBindings::register() method provides a quick start. However, if you need to swap out implementations (e.g., using a custom repository or policy resolver), you can simply override the definitions after calling register(), or write your own binding logic entirely.
// 1. Register default bindings
VerificationBindings::register($builder);
// 2. Override with custom implementations
$builder->addDefinitions([
// Replace PDO with a Redis repository
VerificationCodeRepositoryInterface::class => \DI\autowire(RedisVerificationCodeRepository::class),
// Replace the default policy resolver
VerificationCodePolicyResolverInterface::class => \DI\autowire(CustomPolicyResolver::class),
]);By decoupling the instantiation logic from the domain services, the module remains completely framework-agnostic while still offering a straightforward integration path via PHP-DI.