<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
aurimasniekis / doctrine-json-object-type example snippets
use Doctrine\DBAL\Types\Type;
Type::addType('json_object', 'AurimasNiekis\DoctrineJsonObjectType\JsonObjectType');
use AurimasNiekis\DoctrineJsonObjectType\JsonObject;
class ValueObject implements JsonObject
{
private $name;
public function setName($name)
{
$this->name = $name;
}
public function getName()
{
return $this->name;
}
public static function fromJson(array $data)
{
$inst = new self();
$inst->setName($data['name']);
return $inst;
}
public function jsonSerialize()
{
return [
'name' => $this->getName()
];
}
}
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="entity")
*/
class Entity
{
/**
* @var int
*
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* "json_object" is extended "json" type
*
* @var ValueObject
*
* @ORM\Column(type="json_object)
*/
private $value;
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @return ValueObject
*/
public function getValue()
{
return $this->value;
}
/**
* @param ValueObject $value
*/
public function setValue(ValueObject $value)
{
$this->value = $value;
}
}