marvin255/value-object-bundle

Set of value objects for Dotrine in Symfony.

Maintainers

Package info

github.com/marvin255/value-object-bundle

Type:symfony-bundle

pkg:composer/marvin255/value-object-bundle

Statistics

Installs: 67

Dependents: 0

Suggesters: 0

Stars: 0

v0.1.2 2026-04-03 22:57 UTC

This package is auto-updated.

Last update: 2026-04-06 15:41:41 UTC


README

Latest Stable Version Total Downloads License Build Status

Symfony bundle that provides Doctrine types for common value objects such as Email, Uri, String, Integer, and FileInfo.

Installation

Install the package via Composer:

composer require marvin255/value-object-bundle

Configuration

Add the bundle to your config/bundles.php (if not done automatically):

return [
    // ...
    Marvin255\ValueObjectBundle\Marvin255ValueObjectBundle::class => ['all' => true],
];

Usage

The bundle provides Doctrine DBAL types that automatically convert database values to value objects and vice versa.

Supported Value Object Types

  • marvin255_string - StringValueObject
  • marvin255_non_empty_string - StringNonEmptyValueObject
  • marvin255_email - EmailValueObject
  • marvin255_uri - UriValueObject
  • marvin255_file_info - FileInfoValueObject
  • marvin255_integer - IntValueObject
  • marvin255_non_negative_integer - IntNonNegativeValueObject
  • marvin255_positive_integer - IntPositiveValueObject

Define Entity Properties

Use the Doctrine types in your entity mapping:

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;
use Marvin255\ValueObject\EmailValueObject;
use Marvin255\ValueObject\StringValueObject;

#[ORM\Entity]
class User
{
    #[ORM\Column(type: 'marvin255_string')]
    private ?StringValueObject $name = null;

    #[ORM\Column(type: 'marvin255_email')]
    private EmailValueObject $email;

    public function setEmail(EmailValueObject $email): void
    {
        $this->email = $email;
    }

    public function getEmail(): EmailValueObject
    {
        return $this->email;
    }
}

Working with Value Objects

Create and work with value objects naturally in your code:

use Marvin255\ValueObject\EmailValueObject;
use Marvin255\ValueObject\StringValueObject;

$email = new EmailValueObject('user@example.com');
$name = new StringValueObject('John Doe');

$user->setEmail($email);
$user->setName($name);

$repository->save($user);

The bundle automatically handles conversion between value objects and their database representations.