PHPackages                             romuloar/rom.domain - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. romuloar/rom.domain

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

romuloar/rom.domain
===================

🧠 RomBaseDomain – Your Validatable Domain Base Class for PHP. Automatic and custom validation for domain models, with Symfony Validator integration.

v1.0.1(11mo ago)01MITPHPPHP &gt;=8.0CI passing

Since May 27Pushed 11mo agoCompare

[ Source](https://github.com/romuloar/rom.domain-php)[ Packagist](https://packagist.org/packages/romuloar/rom.domain)[ Docs](https://github.com/romuloar/rom.domain-php)[ RSS](/packages/romuloar-romdomain/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (3)Used By (0)

🧠 RomBaseDomain – Your Validatable Domain Base Class (PHP)
==========================================================

[](#-rombasedomain--your-validatable-domain-base-class-php)

Welcome, dev! 👋

This package helps you create cleaner and more robust domain models by centralizing business rule validation. It combines automatic validation (using Symfony Validator) and custom validation, making it easy to use in modern PHP APIs and applications.

---

💡 What is it?
-------------

[](#-what-is-it)

`RomBaseDomain` is an abstract base class for your domain models. By inheriting from it, you get:

- ✅ Automatic field validation (required, range, email, etc.) via Symfony Validator
- 🧠 Support for custom validation by overriding the `validate()` method
- 📋 Serializable validation error list for APIs/frontends
- 🛡️ Internal methods are not exposed when serializing to JSON

### Naming conventions:

[](#naming-conventions)

- Prefix `List` for lists
- Suffix `Domain` for domain models
- Suffix `DataTransfer` for DTOs

---

🚀 How to use
------------

[](#-how-to-use)

### 1. Installation

[](#1-installation)

```
composer require romuloar/rom.domain-php
```

### 2. Example usage

[](#2-example-usage)

```
use RomDomain\UserDomain;

$user = new UserDomain();
$user->name = '';
$user->age = 15;
$user->email = 'not-an-email';
$user->username = 'usr';
$user->phoneNumber = 'abc';
$user->website = 'not-a-url';
$user->password = '123456';
$user->confirmPassword = '654321';

$isValid = $user->isValidDomain(); // false
$errors = $user->getValidationErrors();

foreach ($errors as $error) {
    echo "Field: {$error->field} | Message: {$error->message}\n";
}
```

### 3. Example API response

[](#3-example-api-response)

```
{
  "success": false,
  "errors": [
    { "field": "name", "message": "The Name field is required." },
    { "field": "age", "message": "The field Age must be between 18 and 120." },
    { "field": "email", "message": "The Email field is not a valid e-mail address." },
    { "field": "username", "message": "The field Username must be a string with a minimum length of 6 and maximum of 12." },
    { "field": "phoneNumber", "message": "The PhoneNumber field is not a valid phone number." },
    { "field": "website", "message": "The Website field is not a valid URL." },
    { "field": "", "message": "'ConfirmPassword' and 'Password' do not match." }
  ]
}
```

### 4. Custom validation

[](#4-custom-validation)

Just override the `validate()` method and use `addValidationError($field, $message)` in your domain class.

---

📦 Dependencies
--------------

[](#-dependencies)

- PHP &gt;= 8.0
- symfony/validator ^7.0

For running tests:

- phpunit/phpunit ^10.0

---

📄 License
---------

[](#-license)

MIT

---

Author
------

[](#author)

Romulo Ribeiro
Instagram: [@romuloar](https://instagram.com/romuloar)

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance50

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity43

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 ~0 days

Total

2

Last Release

356d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/0cef3de36e5e4864aac8475082041920dcdd31465ce8b2b0ece1a24ba696b589?d=identicon)[romuloar](/maintainers/romuloar)

---

Top Contributors

[![romuloar](https://avatars.githubusercontent.com/u/9424233?v=4)](https://github.com/romuloar "romuloar (3 commits)")

---

Tags

phpvalidationDomain Driven Designddddomainsymfony-validator

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/romuloar-romdomain/health.svg)

```
[![Health](https://phpackages.com/badges/romuloar-romdomain/health.svg)](https://phpackages.com/packages/romuloar-romdomain)
```

PHPackages © 2026

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