sbooker/doctrine-object-mapping

Doctrine object types mapping support

1.1.0 2022-04-27 14:18 UTC

This package is auto-updated.

Last update: 2024-03-27 19:10:26 UTC


README

Latest Version Software License PHP Version Total Downloads

Maps immutable object and object list to single json field.

Installation

Make sure Composer is installed globally, as explained in the installation chapter of the Composer documentation.

Applications that don't use Symfony

Step 1: Download library

$ composer require sbooker/doctrine-object-mapping 

Step 2: Create and register Doctrine type

class Concrete { /* ... */ }

class ConcreteType extends \Sbooker\DoctrineObjectMapping\ObjectType 
{
    protected function getObjectClass(): string
    {
        return Concrete::class;
    }

    public function getName()
    {
        return 'concrete';
    }
}

\Doctrine\DBAL\Types\Type::addType('concrete', ConcreteType::class);

// Create or get normalizer
$normalizer = new \Symfony\Component\Serializer\Normalizer\ObjectNormalizer(/*...*/);

// Set serializer to type on boot application
/** @var \Sbooker\DoctrineObjectMapping\NormalizableType $type */
$type = \Doctrine\DBAL\Types\Type::getType('concrete');
$type->setNormalizer($normalizer);
$type->setDenormalizer($normalizer);

Applications that use Symfony

Use sbooker/doctrine-object-mapping-bundle

License

See LICENSE file.