There are users with different privileges in the system. They privileges are hierarchical
class User{//abstract user not logged in
//function signIn(){}
}
class Guest extends User{
}
class FullUser extends Guest{
static function signUp(){}//create an account
function signOut(){}
}
class Moderator extends FullUser{
function edit(){}//some new method introduced here,never introduced before
}
class Admin extends Moderator{
//can do everything
}
//can use
FullUser::signUP()
Is my architecture good?
Can you advice me anything else?
I was wondering which is the best way to create a user – write a constructor? Or let it be a “factory” function.
function signIn($username, $password)
I’m new to OOP in php, so I accept wise advices, links, etc.
EDIT:
I’m planning to use this role – checking system:
if(!method_exists($user->addComment())) die('Access denied')
What do you think of it?
EDIT 2:
should I create a role table with ROLE in axis X and METHOD in axis Y?
comment | post | editPost | kill
guest 0 0 0 0
fullUser 1 0 0 0
moderator 1 1 1 0
admin 1 1 1 1
And later I should write something like this
function addComment($user){
if(!$ROLES [$this->$role][__FUNCTION__])return;
....
}
Is that better than OOP, wise programmers?
Roles are definitely the way to go.
You can do something simple like letting each user have a
public $roleattribute where $role is just a number (e.g. 9 = admin, 6 = fulluser, 3 = guest).The database table would look like this
In the code you do stuff like ´if ($user->role >= 9)´.
If you want, you can have a role table instead of using just numbers – like this:
You could also make it more advanced where one user can have an array of roles.