1. Go to this page and download the library: Download yokai/doctrine-value-object library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
yokai / doctrine-value-object example snippets
use Doctrine\DBAL\Types\Type;
use Yokai\DoctrineValueObject\Doctrine\Types;
(new Types(['doctrine_type_name' => MyValueObject::class]))
->register(Type::getTypeRegistry());
use Doctrine\DBAL\Types\Type;
use Yokai\DoctrineValueObject\Doctrine\Types;
class Kernel extends BaseKernel
{
private const DOCTRINE_VALUE_OBJECTS = [
'doctrine_type_name' => MyValueObject::class,
];
public function __construct(string $environment, bool $debug)
{
parent::__construct($environment, $debug);
(new Types(self::DOCTRINE_VALUE_OBJECTS))->register(Type::getTypeRegistry());
}
}
use Doctrine\DBAL\Types\Type;
use Yokai\DoctrineValueObject\Doctrine\Types;
#[\Attribute(\Attribute::TARGET_CLASS)]
final readonly class AsValueObject
{
public function __construct(
public string $name,
) {
}
}
#[AsValueObject(MyValueObject::DOCTRINE_TYPE_NAME)]
final class MyValueObject implements \Yokai\DoctrineValueObject\StringValueObject
{
public const DOCTRINE_TYPE_NAME = 'doctrine_type_name';
}
$types = [];
foreach (Attributes::findTargetClasses(AsValueObject::class) as $target) {
/** @var AsValueObject $attribute */
$attribute = $target->attribute;
$types[$attribute->name] = $target->name;
}
(new Types($types))->register(Type::getTypeRegistry());
namespace Yokai\DoctrineValueObject\Tests;
use Doctrine\ORM\Mapping as ORM;
final class Entity
{
#[ORM\Column(type="doctrine_type_name")]
public MyValueObject $status;
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.