How iserranodev/encrypt-bundle works
Main Components
• Bundle Core: Represented by the main class (ISerranoDevEncryptBundle) that hooks the bundle into Symfony.
• Configuration & Dependency Injection: Include the configuration classes (Configuration.php, ISerranoDevEncryptExtension.php) and YAML configuration file (services.yaml) that set up service definitions and environment-based settings.
• Encryption Service: The EncryptService (with its associated encryption and decryption methods) that carries out encryption, decryption, hashing, and reverse operations.
• Attributes: The custom PHP attributes (Encrypted and Hashed) located in src/Attribute, which are used to annotate Doctrine entity properties.
• Event Listeners: Components like EncryptListener and HashListener that intercept Doctrine events to automatically encrypt/decrypt or hash/unhash data as specified.
• Command-line Utility: The GenerateKeyCommand found in src/Command which generates an encryption key file based on configuration.
• Doctrine Integration: Elements under src/Doctrine (e.g., the EncryptAwareMigrationInterface and the custom migration factory), showing how the bundle integrates with Doctrine migrations to support encryption.
• External Configuration File Integration: The project also leverages external configuration files, such as the .env and YAML recipe files, to customize environment settings and bundle behavior.
Relationships and Interactions
• The bundle is integrated into a Symfony application via Composer and enabled in the bundles configuration.
• When a Doctrine entity with the #[Encrypted] or #[Hashed] attribute is processed, the associated event listeners (EncryptListener and HashListener) intercept lifecycle events to invoke the EncryptService.
• The EncryptService uses defined encryption keys and environment configurations (from .env and YAML files) to conduct encryption or decryption.
• During database migrations, the bundle supports migrations via an interface (EncryptAwareMigrationInterface) to ensure that data remains integrated with encryption operations.
• The command GenerateKeyCommand ties into the overall system by producing the necessary encryption key file usually stored in the “encryption/” directory.
Architectural Patterns and Design Principles
• Modular Design: Each concern (attributes, event listeners, service, configuration, migrations) is separated by its responsibility.
• Dependency Injection: Core services and configurations are injected using Symfony’s DI container.
• Event-Driven Processing: Automatic encryption and decryption handling is triggered via Doctrine ORM’s event listeners.
• Extensibility: The use of custom attributes and interfaces allows developers to easily integrate and extend bundle functionalities.
Relevant Technologies/Frameworks
• Symfony Framework: The bundle is built specifically for Symfony.
• Doctrine ORM: Integration with entity lifecycle events for automatic encryption/hashing.
• Composer: For dependency management.
• YAML and Environment Variable Configuration if adjustments are needed.
• Optionally, external libraries like “paragonie/halite” for cryptographic implementations (as mentioned in the README for encryption methods).