My business case has a hierarchy above the user class (e.g. a contact only or a member without logins). But now I'm worried how the BaseUser which I have to extend from the FOSUserBundle can extend my Member class?
I don't really understand what is Your member class but in FOS docs its written
Your first job, then, is to create the
User class for your application. This class can look and act however
you want: add any properties or methods you find useful. This is your
User class.
The bundle provides base classes which are already mapped for most
fields to make it easier to create your entity.
You don't have to extend BaseUser, it is provided just to make installation easier. it should work if You copy it to Your own bundle and make it extend Your member class.
Related
I am extending from FOSUserBundle's abstract User class as described in the documentation.
I see that there Doctrine/ORM's mapping-annotations in the class.
Does this mean that - if I extend from the class - the properties defined in the abstract class won't get persisted?
Do I need to manually edit the bundle's abstract class or has the mapping been defined elsewhere?
FOSUserBundle uses XML mappings.
That's the reason there are no annotations in the abstract User class.
doctrine mappings can be found in Resources/config/doctrine.
propel schema can be found in Resources/config/propel.
I'm currently trying to understand how to develop DDD classes, without any assumptions on the implementations that may need to use them. I managed to develop a small structure, made of a user object called User which implements a IUser interface so I can keep an efficient abstraction for reuse purposes.
I now would like to use this user object in a concrete implementation, by using Symfony2 in my case. In order to benefit from the Symfony security layer, my user object needs to implement the UserInterface interface provided by Symfony.
If I understand the pattern correctly, this would be a great opportunity to implement an Adapter called UserAdapter which would allow me to make my user class work with Symfony. So far so good, this works perfectly fine. But here goes my problem :
Suppose I add a Comment class in my DDD lib, which has an $user attribute. To bind a user to a comment, I use for instance a setUser() setter which requires anything that implements the IUser interface. If tomorrow I want to change the user class to be used in this context, all I need is a new user class that implements the IUser interface.
But in my concrete implementation, in a Symfony controller for example, I'm using an instance of the UserAdapter class, which implements the Symfony UserInterface interface. When calling the setUser() setter on my Comment object, the interface doesn't match.
What am I missing?
Am I using the Adapter pattern in a wrong way, should I use a different strategy in my implementation?
There are two solutions that come to my mind. One solution works with inheritance, one with delegation.
Inheritance
In your UserAdapter class extend from your DDD User class. Also implement the Symfony2 UserInterface in the adapter. Now implement the methods from the UserInterface by using the attributes from the parent class.
Delegation
Same as in the inheritance case the UserAdapter class must implement the Symfony2 UserInterface. But now you create an association from the adapter to the concrete user class. So your adapter "has one" user. To avoid having adapters without a user you can require a user in the adapters constructor. Then you can call the setUser method with setUser($userAdapter->getUser()).
I am trying to implement my own userBundle and i am am getting ideas from FOSUSerBunle.
WHile i see the code , i notice that he first created the UserInterface and then implements that interface on user entity.
I want to know that what is the use of userInterface , why can't i directly make UserClass
An interface is an object oriented programming concept. In PHP, it declares (not defines) a set of public methods. Any class that implements an interface is required to define the methods declared within the interface. You can think of an interface as a contract.
Using interfaces allows you to 'program to an interface'.
In the case of FOSUserBundle, the UserInterface is meant to be used so that your user entity will actually work with the rest of the bundle. By agreeing to the contract of UserInterface, your user entity will contain the necessary methods that FOSUserBundle requires of it. Furthermore, you may see type hinting being used within FOSUserBundle that specifically refers to UserInterface, as opposed to a concrete user class.
If you're rolling your own user bundle, you don't need to implement any interfaces, as the design is completely up to you. But, it sounds like you're reinventing the wheel here, so I recommend just using FOSUserBundle.
So you can create you own user class that implements this interface. This way you can integrate your class with FOSUserBundle easily
Does anyone know if their exists a bundle that supports multiple user types?
In my example I want a generic User class (e.g. FOSUser) that I will extend from to use for my CompanyUser class and EmployeeUser class, so those 2 classes will have all the features of a User but with their own class properties and methods.
From what I read it looks like FOSUser only supports a single type.
There is no Bundle. You should use Groups or if there is no other ways UserEntities extending the UserBaseModel. These should be available through a custom UserProvider
you can use RollerworksMultiUserBundle
I'm new to Kohana and I'm trying to build an application using the ORM module. I created my own user module containing stuff like login, account creating etc. The problem however is that I can't seem to create a user model in my own user module extending the ORM one. If I understand kohana correctly I should name my user model: Model_User. The problem is, the ORM model I'm trying to extend is also called Model_User.
The reason I'm trying to create my own model is so I can add some extra methods and checks without modifying with the ORM user model.
So my question is:
How do I create a user model in my own module that extends the ORM user model?
You can extend pretty much everything in Kohana via the transparent class extensions: http://kohanaframework.org/3.2/guide/kohana/extension
In this case, the default ORM Model_User class is an empty (transparent) class that extends Model_Auth_User.
So if you want to add new methods to this model, just create a new Model_User model class that extends Model_Auth_User, in your module.
Due to Kohana's cascading file system, the model stored in your module will be used. http://kohanaframework.org/3.2/guide/kohana/files
[edit] Important to note, the order in which you enable the modules is important, see http://kohanaframework.org/3.2/guide/kohana/modules