tourze / doctrine-ip-bundle
Doctrine+IP
Installs: 1 235
Dependents: 5
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^8.1
- doctrine/doctrine-bundle: ^2.13
- doctrine/orm: ^2.20 || ^3.0
- doctrine/persistence: ^3.1 || ^4
- psr/log: ^3|^2|^1
- symfony/config: ^6.4
- symfony/dependency-injection: ^6.4
- symfony/framework-bundle: ^6.4
- symfony/http-kernel: ^6.4
- symfony/property-access: ^6.4
- symfony/service-contracts: ^3.5
- symfony/yaml: ^6.4 || ^7.1
- tourze/bundle-dependency: 0.0.*
- tourze/doctrine-entity-checker-bundle: ~0.0.8
Requires (Dev)
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2025-04-25 14:28:42 UTC
README
A Symfony bundle that automatically tracks and records IP addresses for entity creation and updates using PHP 8.1 attributes.
Features
- Automatically tracks IP addresses when entities are created
- Automatically tracks IP addresses when entities are updated
- Uses PHP 8.1 attributes for simple configuration
- Supports private properties through PropertyAccessor
- Thread-safe implementation with ResetInterface
- Integrates with Symfony's request cycle to capture client IPs
- Zero configuration required - works out of the box
Requirements
- PHP 8.1 or higher
- Symfony 6.4 or higher
- Doctrine ORM 2.20/3.0 or higher
- Doctrine Bundle 2.13 or higher
Installation
composer require tourze/doctrine-ip-bundle
The bundle will be automatically registered thanks to Symfony Flex.
Usage
Add the appropriate attributes to your entity properties:
use Tourze\DoctrineIpBundle\Attribute\CreateIpColumn; use Tourze\DoctrineIpBundle\Attribute\UpdateIpColumn; class YourEntity { // This property will store the IP address when the entity is created #[CreateIpColumn] private ?string $createIp = null; // This property will store the IP address when the entity is updated #[UpdateIpColumn] private ?string $updateIp = null; // Getters and setters public function getCreateIp(): ?string { return $this->createIp; } public function getUpdateIp(): ?string { return $this->updateIp; } }
How It Works
The bundle works by listening to Doctrine's lifecycle events:
- It registers event listeners for Doctrine's
prePersist
andpreUpdate
events - It captures the client IP from the request through Symfony's
kernel.request
event - When an entity is created or updated, it checks for properties with the appropriate attributes
- If found, it automatically sets the client IP to those properties
Configuration
The bundle is auto-configured. No additional configuration is needed.
Dependencies
This bundle automatically requires and configures:
tourze/doctrine-entity-checker-bundle
License
This bundle is licensed under the MIT License.