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: 91

Dependents: 0

Suggesters: 0

Stars: 0

v0.2.0 2026-04-14 20:55 UTC

This package is auto-updated.

Last update: 2026-04-14 20:56:42 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_positive_integer - IntPositiveValueObject
  • marvin255_negative_integer - IntNegativeValueObject
  • marvin255_non_negative_integer - IntNonNegativeValueObject
  • marvin255_non_positive_integer - IntNonPositiveValueObject
  • marvin255_float - FloatValueObject
  • marvin255_percentage - PercentageValueObject
  • marvin255_bc_math_number - BcMathNumberValueObject (requires bcmath PHP extension)

Optional Types

Some types are only available when their corresponding PHP extensions are installed:

BcMath Type (marvin255_bc_math_number)

The BcMathNumberValueObject type provides arbitrary-precision decimal arithmetic using PHP's bcmath extension. It's automatically registered only if the bcmath extension is enabled.

To enable bcmath on your PHP installation, ensure it's installed and uncommented in php.ini:

extension=bcmath

If the extension is not available, the type will not be registered but the rest of the bundle will continue to function normally.

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.