Symfony get curent entity from custom DBAL type

I have class that define custom type and i want to make validation based on class that call that type.

Its in purpose of having 2 tables when one is managed by symfony and other is not for yet.

The table that not managed by symfony ned value of 0, when is null.

namespace AppDBALTypesNull;

use DoctrineDBALTypesIntegerType as DeafaultType;
use DoctrineDBALPlatformsAbstractPlatform;

class IdentityType extends DeafaultType
{
    const NULLIDENTITY = 'nullidentity';

    public function getName()
    {
        return self::NULLIDENTITY;
    }

    public function convertToDatabaseValue($value, AbstractPlatform $platform)
    {
        #some logic
        if ($entity instanceof ClassNotManagedBySymfony) {
            return $value === null? 0: (int)$value;
        }
        return $value
    }

    public function convertToPHPValue($value, AbstractPlatform $platform)
    {
        #some logic
        if ($entity instanceof ClassNotManagedBySymfony) {
            return $value === 0? null: (int)$value;
        }
        return $value;
    }
}

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *