0 votes

Hi,

I'm using dynamic relations with "implements" and "traits".

How can I import this relations into Skipper?

    public function getSubscribedEvents()
{
    return [
        'loadClassMetadata',
    ];
}

/**
 * @param LoadClassMetadataEventArgs $eventArgs
 */
public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs)
{
    /** @var ClassMetadata $metadata */
    $metadata = $eventArgs->getClassMetadata();
    $reflectionClass = new \ReflectionClass($metadata->getName());
    $implements = class_implements($metadata->getName());

    if (in_array('AppBundle\Entity\Interfaces\ShareInterface', $implements)) {
        /** @noinspection PhpUndefinedMethodInspection */
        $metadata->mapManyToMany([
            'targetEntity' => Share::CLASS,
            'cascade' => ['persist','remove'],
            'fieldName' => 'shares',
        ]);
    }
asked Jul 23, 2017 in Solved by MarcoDL (150 points)
recategorized Jan 4 by ludek.vodicka

2 Answers

0 votes
Best answer

So, you need to export your entity to php file. Then you need to rewrite "class" keyword to "trait" in any text editor. And during next export Skipper keep it as is and proceed only update to @ORM properties.

This should solve your problem in the most elegant way without the necessity to configure anything in Skipper.

This feature is added to new beta released here https://support.skipper18.com/402/downloads-skipper-beta

answered Jan 4 by ludek.vodicka Skipper developer (126,570 points)
0 votes

Hi,
unfortunately, traits aren't supported for now. It's because there is very low interest in this feature and on the other side complexity of such feature is very high.

answered Jul 25, 2017 by ludek.vodicka Skipper developer (126,570 points)

Hello Ludek,

We have recently discovered the power of traits and are starting using it.
Currently, we make a region in a bundle for traits and simply create normal entities.
We manually replace "class" by "trait" and add the "use" in the required entities by hand.
It all works fine, except, "trait" is always replaced by "class" on export to ORM.

Our basic need would be to be able to tag an entity as trait, so the the class becomes / stays "trait", this could be a simple attribute on the entity which puts trait instead of class during export.

More extensive support would be to actually use the traits in other entities, but this could come later.

Doctrine2, Symfony3, PHP 5.6+

Best regards

Michael

Hi Michael,

I believe that such simple tag would be possible I will discuss it with my colleagues and let you know.

Hello Ludek,

any progress or plans on this simplified feature ?

Thank you very much

Best regards

Hi Michiel,

sorry for long delay. To be honest, I forgot to reply you and to release this feature.

The bad news is that it is not possible to change "class" to "trait" during export in existing php files with existing Skipper export mechanism.

The good news is that my colleague has found another solution but I forgot to merge it to production.

He was able to implement a small hack/update into the export core which handles "class" and "trait" keywords as the same thing.

So, you need to export your entity to php file. Then you need to rewrite "class" keyword to "trait" in any text editor. And during next export Skipper keep it as is and proceed only update to @ORM properties.

This should solve your problem in the most elegant way without the necessity to configure anything in Skipper.

This feature is added to new beta released here https://support.skipper18.com/402/downloads-skipper-beta

Please let me know if it works as expected.

Hello Ludek,

Works fine for me, thank you !

enter image description here

Perfect. Glad to hear that.