Discriminator Mapping for Embeddables #6419

Closed
opened 2026-01-22 15:32:54 +01:00 by admin · 1 comment
Owner

Originally created by @Timmypedia on GitHub (Mar 4, 2020).

Feature Request

Q A
New Feature yes
RFC yes
BC Break no

Summary
Some times (if you work with a Layered Architecture) you came to this weird situation :

Code

<?php

/**
 * Domain Layer
 */
Interface ApiVersion
{

    public static function fromString(string $data): ApiVersion;

    public function toString(): string;
}

/**
 * Domain Layer
 */
abstract class OAuth
{
    protected ApiVersion $apiVersion;
}

/**
 * Infrastructure Layer
 */
final class FacebookApiVersion implements ApiVersion
{

    private string $version;

    private function __construct(string $version)
    {
        $this->version = $version;
    }

    public static function fromString(string $data): ApiVersion
    {
        // multiple checks if the String is a Valid API Version string for Facebook
        return new FacebookApiVersion($data);
    }

    public function toString()
    {
        return $this->version;
    }
}

oAuth is our Entity right now, and ApiVersion should be the Embeddable, but it depends on the API i would like to call with that.

You have multiple implementations for a Value object in a Super Class. It would be nice, if I could describe a discriminator mapping for a Value object that is actually an Interface.

Is there a Workaround for such cases right now?

Originally created by @Timmypedia on GitHub (Mar 4, 2020). **Feature Request** Q | A -- | -- New Feature | yes RFC | yes BC Break | no **Summary** Some times (if you work with a Layered Architecture) you came to this weird situation : **Code** ```php <?php /** * Domain Layer */ Interface ApiVersion { public static function fromString(string $data): ApiVersion; public function toString(): string; } /** * Domain Layer */ abstract class OAuth { protected ApiVersion $apiVersion; } /** * Infrastructure Layer */ final class FacebookApiVersion implements ApiVersion { private string $version; private function __construct(string $version) { $this->version = $version; } public static function fromString(string $data): ApiVersion { // multiple checks if the String is a Valid API Version string for Facebook return new FacebookApiVersion($data); } public function toString() { return $this->version; } } ``` oAuth is our Entity right now, and ApiVersion should be the Embeddable, but it depends on the API i would like to call with that. You have multiple implementations for a Value object in a Super Class. It would be nice, if I could describe a discriminator mapping for a Value object that is actually an Interface. Is there a Workaround for such cases right now?
admin closed this issue 2026-01-22 15:32:55 +01:00
Author
Owner

@beberlei commented on GitHub (Mar 15, 2020):

Yes, you can store the object using the DBAL object type, which serializes it into the database as a BLOB. If you want it a bit nicer, you can store it as JSON and have a second column with the type and "hydrate" the objects yourself in getters.

@beberlei commented on GitHub (Mar 15, 2020): Yes, you can store the object using the DBAL `object` type, which serializes it into the database as a BLOB. If you want it a bit nicer, you can store it as JSON and have a second column with the type and "hydrate" the objects yourself in getters.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6419