marvin255 / value-object-bundle
Set of value objects for Dotrine in Symfony.
Package info
github.com/marvin255/value-object-bundle
Type:symfony-bundle
pkg:composer/marvin255/value-object-bundle
Requires
- php: >=8.3
- doctrine/doctrine-bundle: ^2.0|^3.0
- doctrine/orm: ^3.0
- marvin255/value-object: ^0.2
- symfony/framework-bundle: ^6.0 | ^7.0|^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- infection/infection: ^0.32
- phpunit/phpunit: ^12.0|^13.0
- vimeo/psalm: ^6.0
This package is auto-updated.
Last update: 2026-04-06 15:41:41 UTC
README
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- StringValueObjectmarvin255_non_empty_string- StringNonEmptyValueObjectmarvin255_email- EmailValueObjectmarvin255_uri- UriValueObjectmarvin255_file_info- FileInfoValueObjectmarvin255_integer- IntValueObjectmarvin255_non_negative_integer- IntNonNegativeValueObjectmarvin255_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.