upscale/doctrine-value-object-bundle

Symfony bundle for yokai/doctrine-value-object

1.0.1 2023-06-09 03:26 UTC

This package is auto-updated.

Last update: 2024-11-09 20:39:51 UTC


README

This package wraps yokai/doctrine-value-object in a bundle to simplify its use in Symfony projects.

Features:

  • Zero config setup
  • Attribute annotation

Installation

Install via Composer as a dependency:

composer require upscale/doctrine-value-object-bundle

Usage

Attribute Annotation

Register a value object using an attribute annotation (available since PHP 8):

use Upscale\DoctrineValueObjectBundle\Attribute\ValueObject;
use Yokai\DoctrineValueObject\StringValueObject;

#[ValueObject]
class PhoneNumber implements StringValueObject {...}

Reference the value object type by an underscore separated short class name:

#[Entity]
class Person
{
    #[Column(type: 'phone_number')]
    private PhoneNumber $phone;
    
    // ...
}

Type Naming

You can customize the type name, including use a fully-qualified class name, for example:

#[ValueObject(type: PhoneNumber::class)]
class PhoneNumber implements StringValueObject {...}
#[Entity]
class Person
{
    #[Column(type: PhoneNumber::class)]
    private PhoneNumber $phone;
    
    // ...
}

Contributing

Pull Requests with fixes and improvements are welcome!

License

Copyright © Upscale Software. All rights reserved.

Licensed under the Apache License, Version 2.0.