sbooker/doctrine-object-mapping

Doctrine object types mapping support

1.2.0 2024-10-22 15:49 UTC

This package is auto-updated.

Last update: 2024-10-22 15:50:39 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.