dev-master
9999999-dev http://github.com/matthiasnoback/doctrine-orm-value-objectIntroduces value objects to Doctrine ORM
MIT
The Requires
The Development Requires
value object doctrine orm
Wallogit.com
2017 © Pedro Peláez
Introduces value objects to Doctrine ORM
WARNING: this library is not ready for production yet, (*2)
This library provides the tools for working with value objects and Doctrine entities., (*3)
This is the way you could persist a PhoneNumber value object as a field of a Person entity using the ValueObject annotation:, (*4)
<?php
namespace Acme\DemoBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Acme\DemoBundle\Value\PhoneNumber;
use Noback\DoctrineOrmValueObject\Annotation\ValueObject;
/**
* @ORM\Entity
*/
class Person
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ValueObject(class="Acme\DemoBundle\Value\PhoneNumber")
*/
private $phoneNumber;
private $phoneNumber_number;
private $phoneNumber_since;
public function getId()
{
return $this->id;
}
public function setPhoneNumber(PhoneNumber $phoneNumber)
{
$this->phoneNumber = $phoneNumber;
}
public function getPhoneNumber()
{
return $this->phoneNumber;
}
}
The Person entity should have a corresponding property for each of the properties of the PhoneNumber class., (*5)
<?php
namespace Acme\DemoBundle\Value;
use Doctrine\ORM\Mapping\Column;
class PhoneNumber
{
/**
* @Column(type="string", length=255)
*/
private $number;
/**
* @Column(type="datetime")
*/
private $since;
public function __construct($number, \DateTime $since)
{
$this->number = $number;
$this->since = $since;
}
public function getNumber()
{
return $this->number;
}
public function getSince()
{
return $this->since;
}
}
The PhoneNumber class contains the column definitions for the corresponding fields of the Person entity., (*6)
Event listeners make sure that:, (*7)
Person entity is being persisted or updated, the fields of the entity will contain the values from the PhoneNumber value object.Person entity is loaded from the database, the phoneNumber field will contain a PhoneNumber object. Its values will be copied from the designated entity fields.PhoneNumber value object will be added to the Person entity's schema.Introduces value objects to Doctrine ORM
MIT
value object doctrine orm