This forum is in READ-ONLY mode.
You can look around, but if you want to ask a new question, please use Stack Overflow.

Access default user provider - best practice

This forum is for non code-based questions, best practises, IDEs, version control tools, work opportunities, etc.

Access default user provider - best practice

by hemuveg » Sun Sep 28, 2014 2:32 pm

Hi All!

I would like to ask for some help to find the right direction.
I am creating a bundle which manages Shipping addressess of users. (actually not exactly this kind of functionality, but easy to describe my problem with this).
The main point:
If this bundle registered, the user object is extended with some more related entities.

So in this bundle I have to connect addressess to users. I would like to create it 100% reusable, so in my viewpoint, the only important information about the user is the ID which should exist in any type of user provider.
The bundle uses doctrine for database handling and yaml for mapping.

My headache is how to create the bundle in the 'best way':
- Simply create the address class and store the user_id in it without any real relation (w/o doctrine manytoone)
- Create a User object in my bundle which extends the default user and use this entity in my bundle, and connect addresses to this entity
This solution makes easy to create the yaml relation, because i can use an exact entity to map to in yaml.
- Create the configuration of the bundle to somehow use the default user class and connect the addresses to it.

I would like to get some advice about the last two option. The first looks easy, but in my head the third one looks "beautiest".

Second option(own user class):
Code: Select all
namespace NAMESPACE\Bundlename;
use the_default_user_object_based_on_app_config as BaseUser;
class myUser extends BaseUser {
//could be empty
}

Third option (yml):
Code: Select all
NAMESPACE\Bundlename\Entityname:
    type:  entity
    table: some_table_name
    id:
        id:
            type: integer
            generator:
                strategy: AUTO
    fields:
        field_one:
            type:   string
            length: 100
    oneToMany:
        user:
            targetEntity: %would_be_the_default_user_class%
            joinColumn:
                name:                   user_id
                referencedColumnName:   id

It is possible of course that my whole logic puts me to the wrong way, so help me to find out what would be the best solution please. :)
Maybe I should not use yml mapping, or should not have to take care which object is the default user, i am not sure.

The addressess are managed only by the user, so the first option could be a working one too, but I am trying to implement this function in the way it should be implemented.

Hope my question/problem is clear and I put it into the right board!

Regards:
hemuveg
hemuveg
Junior Member
 
Posts: 1
Joined: Sun Sep 28, 2014 2:03 pm