PHPackages                             tourze/doctrine-ip-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. tourze/doctrine-ip-bundle

ActiveLibrary

tourze/doctrine-ip-bundle
=========================

Doctrine+IP

1.1.1(4mo ago)022.7k20MITPHPCI passing

Since Mar 25Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/doctrine-ip-bundle)[ Packagist](https://packagist.org/packages/tourze/doctrine-ip-bundle)[ RSS](/packages/tourze-doctrine-ip-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (22)Versions (9)Used By (20)

Doctrine IP Bundle
==================

[](#doctrine-ip-bundle)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Version](https://camo.githubusercontent.com/eb25cd58cc11f6b28e912dece1adae3aac06c66225f1b143f682eb6f349fc1cb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f746f75727a652f646f637472696e652d69702d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/doctrine-ip-bundle)[![Total Downloads](https://camo.githubusercontent.com/abc8729a83af3c2a62f6a1f2ef6d271d7cb9406d07a59289d2471ab52f9d80be/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f746f75727a652f646f637472696e652d69702d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/doctrine-ip-bundle)[![PHP Version](https://camo.githubusercontent.com/ffd95f2fd158c2c796cabe7281afc64e11b0bbec13bf9afcdd810858938e4a22/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f746f75727a652f646f637472696e652d69702d62756e646c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/tourze/doctrine-ip-bundle)[![License](https://camo.githubusercontent.com/c37128cfb011fb6811694d39d4e5db84e342a3d593f3c27e29deef7edaaec5ca/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f746f75727a652f646f637472696e652d69702d62756e646c652e7376673f7374796c653d666c61742d737175617265)](LICENSE)[![Build Status](https://camo.githubusercontent.com/d6265f36f154bb7f26db8de112889d7a0b299f6a264f8b6c5bb273a333cc2844/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f746f75727a652f646f637472696e652d69702d62756e646c652f63692e796d6c3f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://github.com/tourze/doctrine-ip-bundle/actions)[![Code Coverage](https://camo.githubusercontent.com/6fb8032f100555571ca4d0495bc5b84c7270b3cfb1fac738ebaca883372cec27/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f746f75727a652f646f637472696e652d69702d62756e646c653f7374796c653d666c61742d737175617265)](https://codecov.io/gh/tourze/doctrine-ip-bundle)

A Symfony bundle that automatically tracks and records IP addresses for entity creation and updates using PHP 8.1 attributes. This bundle provides seamless integration with Doctrine ORM to capture client IP addresses during entity lifecycle events.

Features
--------

[](#features)

- 🔍 **Automatic IP Tracking**: Automatically captures client IP addresses during entity creation and updates
- 🏷️ **PHP 8.1 Attributes**: Uses modern PHP attributes for simple, declarative configuration
- 🔐 **Private Property Support**: Works with private properties through Symfony's PropertyAccessor
- 🧵 **Thread-Safe**: Implementation with ResetInterface for proper request isolation
- 🔄 **Seamless Integration**: Integrates with Symfony's request cycle and Doctrine lifecycle events
- 📦 **Zero Configuration**: Works out of the box with no additional setup required
- 🎯 **Flexible**: Supports both individual attributes and convenient traits

Installation
------------

[](#installation)

### Requirements

[](#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

### Install via Composer

[](#install-via-composer)

```
composer require tourze/doctrine-ip-bundle
```

The bundle will be automatically registered thanks to Symfony Flex.

Quick Start
-----------

[](#quick-start)

### Method 1: Using Individual Attributes

[](#method-1-using-individual-attributes)

Add the appropriate attributes to your entity properties:

```
use Tourze\DoctrineIpBundle\Attribute\CreateIpColumn;
use Tourze\DoctrineIpBundle\Attribute\UpdateIpColumn;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class YourEntity
{
    // This property will store the IP address when the entity is created
    #[CreateIpColumn]
    #[ORM\Column(length: 45, nullable: true)]
    private ?string $createIp = null;

    // This property will store the IP address when the entity is updated
    #[UpdateIpColumn]
    #[ORM\Column(length: 45, nullable: true)]
    private ?string $updateIp = null;

    // Getters and setters
    public function getCreateIp(): ?string
    {
        return $this->createIp;
    }

    public function getUpdateIp(): ?string
    {
        return $this->updateIp;
    }
}
```

Method 2: Using Convenient Traits
---------------------------------

[](#method-2-using-convenient-traits)

For easier implementation, use the provided traits:

```
use Tourze\DoctrineIpBundle\Traits\IpTraceableAware;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class YourEntity
{
    use IpTraceableAware;

    // Your other properties...
}
```

Or use the creation-only trait:

```
use Tourze\DoctrineIpBundle\Traits\CreatedFromIpAware;
use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class YourEntity
{
    use CreatedFromIpAware;

    // Your other properties...
}
```

Available Attributes and Traits
-------------------------------

[](#available-attributes-and-traits)

### Attributes

[](#attributes)

- **`#[CreateIpColumn]`**: Marks a property to be automatically populated with the client IP address when the entity is first persisted
- **`#[UpdateIpColumn]`**: Marks a property to be automatically populated with the client IP address when the entity is updated

### Traits

[](#traits)

- **`IpTraceableAware`**: Provides both `$createdFromIp` and `$updatedFromIp` properties with getters and setters
- **`CreatedFromIpAware`**: Provides only `$createdFromIp` property with getter and setter

Both traits include the proper Doctrine ORM mapping annotations.

How It Works
------------

[](#how-it-works)

The bundle works by listening to Doctrine's lifecycle events:

1. It registers event listeners for Doctrine's `prePersist` and `preUpdate` events
2. It captures the client IP from the request through Symfony's `kernel.request` event
3. When an entity is created or updated, it checks for properties with the appropriate attributes
4. If found, it automatically sets the client IP to those properties

Configuration
-------------

[](#configuration)

The bundle is auto-configured and requires no additional configuration. It automatically:

- Registers the IP tracking listener with Doctrine
- Configures the PropertyAccessor for private property access
- Sets up the request listener to capture client IP addresses

Advanced Usage
--------------

[](#advanced-usage)

### Custom IP Detection

[](#custom-ip-detection)

The bundle automatically detects client IP addresses using Symfony's `Request::getClientIp()` method, which handles:

- Standard `REMOTE_ADDR` header
- Proxy headers like `X-Forwarded-For`
- Load balancer headers like `X-Real-IP`

### Thread Safety

[](#thread-safety)

The bundle implements Symfony's `ResetInterface` to ensure proper request isolation in long-running processes like ReactPHP or Swoole.

### Existing Values

[](#existing-values)

The bundle respects existing values - if a property already has a value, it will not be overwritten.

Dependencies
------------

[](#dependencies)

This bundle automatically requires and configures:

- `tourze/doctrine-entity-checker-bundle` - For entity validation and checking capabilities

License
-------

[](#license)

This bundle is licensed under the MIT License.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance74

Regular maintenance activity

Popularity21

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~38 days

Recently: every ~52 days

Total

8

Last Release

143d ago

Major Versions

0.0.5 → 1.0.02025-10-31

### Community

Maintainers

![](https://www.gravatar.com/avatar/e354fdb316da535dfa8ba2e9193a473c403b6bc6fb9170778d1dc50e304c6e9d?d=identicon)[tourze](/maintainers/tourze)

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-doctrine-ip-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-doctrine-ip-bundle/health.svg)](https://phpackages.com/packages/tourze-doctrine-ip-bundle)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
