Implement multiple users in Symfony 2 - php

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

Related

Extending ORM classes in CakePHP 3

I would like to extend Query class in order to create function customContain() available in every Table model. How should I do it?
I want to use that BleMethod() in all table models in cakephp. Where I have to add code of that function? Where I have to implements BleMethod?
Unlike Cake2 Cake3 does not feature an application level class like AppModel from where all other classes inherit from. So you have two options:
Trait
Behavior
The behavior can be loaded globally to all models by using the Model.initialize event. And then loading the behavior inside the events callback. Read these pages:
Creating a behavior
Event system
Model / Table callbacks
But that's not what you want
customContain() indicates for me that you want to setup some contains very often. Well, use finders.
Finders can be combined:
$this->Table->find('foo')->find('myContains')->all();
Each custom find will add something to the query object. You can add your custom contains this way.
Read Custom Finder Methods.

Split interface into multiple when using repository pattern in Laravel 5

I have a EloquentCompanyRepository class which implements CompanyRepository interface. The interface consist of such methods as find, all, save and other common methods. Plus it has some methods like saveEmail, saveCall, saveSms. Apart from EloquentCompanyRepository there are some other classes which have saveEmail, saveCall, saveSms methods.
I want to split the CompanyRepository interface into separate files. Basic EloquentRepository and some interfaces like EmailableContract,CallableContract and SmsableContract.
However I don't understand, what will be the binding in the service provider? What interface should I use in controllers? There is a situation when a repository will implement only EloquentRepository and EmailableContract for example. And I can't use both interfaces in controller, since if I want to get a EloquentCompanyRepository class and it implements only these two interfaces, then what should I use in $app->bind?
I just don't like to repeat all these methods like find, all, saveEmail etc in multiple repositories
In Laravel 5 you have something that is called Contextual Binding. You can bind given implementations to different controllers with same requirements like this:
$this->app->when('App\Handlers\Commands\CreateOrderHandler')
->needs('App\Contracts\EventPusher')
->give('App\Services\PubNubEventPusher');
This way you are saying "When CreateOrderHandler needs EventPusher give it an instance of PubNubEventPusher".

Can BaseUser of FOSUserBundle extend my own class?

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.

Do i need to create interface first in symfony2 before main class

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

PHP Addon support N no of Classes finally extend to one class

I am working on a open source project.
My code should support addons features.
I have 6 to 7 client handling classes which finally extend to one class called "clients"
class client1{}
class client2 extends client1{}//contacts
class client3 extends client2{}//files
...
class clients extends client9{}//msging
This is not proper way to do.(still finding for better way)
This script should support addons. Say one addon having few classes
class clientUserManagement{}
Then it should be controllable in
class clients{}
Each class handling different areas of client system.
Right now extending all the class to one class. By using method_exist(), calling the required functionality.
Important
These classes doesn't share any attribute.
All client related functions should be grouped by type in separate files.
If all classes are finally controlled under one classes name, using method_exist() it will be secure to run only client related functions.
Which is the better way to structure it, so that it support addon functions.
You should split things up to encapsualte functionality and then make the classes interact with each other. I would also abstract away basic things to more generic classes that will be used elsewhere.
Client
has a Collection of Contacts - ClientContactCollection
has a Collection of Files - ClientFileCollection
has a Collection of messages - ClientMessageCollection
ClientContact
extends a generic Contact
ClientFile
extends a generic File
ClientMessage
extends a generic Message

Categories