The Maatify\SharedCommon module contains foundational contracts and abstractions intended to be shared across all Maatify modules, such as AdminKernel and Verification. It acts as the backbone defining "how we communicate" core system realities, ensuring consistent behavior, predictability, and reliable testing throughout the entire application ecosystem.
- Framework Agnosticism: By depending on
SharedCommonrather than framework-specific implementations (e.g., global functions liketime()ordate()), modules remain entirely decoupled and reusable across different frameworks. - Unified Interfaces: The module provides standardized interfaces for cross-cutting concerns like time management, security event tracking, and telemetry data collection. This means any module that needs to log an IP address or track a request ID knows exactly which contract to ask.
- Predictable Testing: Establishing a strict
ClockInterfaceallows applications to freeze time during testing, ensuring consistent assertions without mocking global PHP functions or relying on fragile timing conditions. - Telemetry and Security Standardization: Interfaces like
TelemetryContextInterfaceandSecurityEventContextInterfaceguarantee that any module (such as theAuditTrailorVerificationmodules) will receive consistent, well-structured telemetry data (IPs, User Agents, Request IDs) without knowing how the HTTP request is built.
- Time Tracking: Safely generating a new OTP token with a precise expiry time using
ClockInterface->now(). - Security Auditing: Accessing the client IP and User-Agent through
SecurityEventContextInterfaceto track failed login attempts or session manipulations. - Request Tracing: Extracting a Request ID via
TelemetryContextInterfaceto correlate logs across disparate modules during a single HTTP cycle.
- Contract Definition:
SharedCommondefines the interfaces (the "contracts") insideMaatify\SharedCommon\Contracts. - Implementation Implementation:
SharedCommonprovides basic implementations (likeSystemClockinInfrastructure) or expects the broader application to fulfill the contracts (likeTelemetryContextInterface). - Module Dependency: Modules like
VerificationrequireClockInterfaceto manage their internal TTLs andTelemetryContextInterfacefor IP auditing. - Container Binding: The
Bootstraplayer registers these interfaces, binding them to real infrastructure objects provided by the underlying framework. - Execution: When a module needs the current time or the client IP, it calls the
ClockInterfaceorTelemetryContextInterfaceresolved by the DI container.