Search code examples
phpsymfonyoopfoselasticabundlea2lix-translation

Interface and Traits does not work properly


This is some weird behaviour I witnessed today and I wonder why.. I`ll get straight to the point:

So we are using a2lix translations with symfony and fos elasticabundle

class Class
{
    use Translatable;

}

class ClassTranslation  implements \A2lix\I18nDoctrineBundle\Doctrine\Interfaces\OneLocaleInterface
{
    use Translation;

}

In this scenario once I run

php app/console fos:elastica:populate

I`m getting:

[InvalidArgumentException] Parameter 'locale' does not exist.

But the parameter is actually in the trait(from the vendor that include 2 traits translatable methods and translatable properties)

The questions is why does this happen. We have the property from the trait yet once we run the command it does not find it.

Ok now here comes the strange part!

In this scenario everything works as expected:

class Class
{
    use Translatable;

}

class ClassTranslation 
{
    use Translation;

}

If I decide not to implement the interface the command runs smoothly, the interface just forces you to have getter and setter for the locale atribute. I just wonder why does this happen.


Solution

  • This may relates to https://github.com/a2lix/I18nDoctrineBundle/issues/16.

    I don't think this is related to php traits since there wouldn't be an InvalidArgumentException. Maybe the code of the trait is not executed if the interface is not present, so there is no error in this case. Please check the implementation of your trait, maybe do some debug output to see when the code is executed and when the exeption occurs.