kayue / KayueWordpressBundle

A Symfony 2 bundle for providing WordPress repositories and authenticating users (login).
101 stars 43 forks source link

Override the User type so I can implement an interface #66

Open mattsnowboard opened 8 years ago

mattsnowboard commented 8 years ago

I need the users loaded by this bundle to implement an interface so I can use them in place of my other users loaded by FOSUserBundle.

I was able to almost do this by making a child bundle to override the Entitiy/User.php file with a new one. I had to just copy-paste the entity from the bundle and add my interface and implement the methods. The problem is, since the Doctrine mapping is already in the annotations in this bundle, I now have two entities that use the same table.

I added resolve_target_entities to my config which seemed to work:

doctrine:
    orm:
        auto_generate_proxy_classes: %kernel.debug%
        default_entity_manager:   default
        entity_managers:
            default:
                connection: default
                mappings:
                    StudyMainBundle: ~
                    FOSUserBundle: ~
            wordpress:
                connection: wordpress
                mappings:
                    KayueWordpressBundle: ~
                    StudyWordPressBundle: ~
        resolve_target_entities:
            Kayue\WordpressBundle\Entity\User: Study\WordPressBundle\Entity\User

The problem is that my unittests/functional tests always load fixtures and Doctrine doesn't like that it finds two entities that map to the table wp_users.

Could you make some change so that users can be overridden? Maybe use the MappedSuperclass pattern that FOSUserBundle does https://symfony.com/doc/1.3.x/bundles/FOSUserBundle/index.html ? If there is some other way I can accomplish this, please let me know.