For example, we have a class:
class A
{
protected $user;
public function __construct(GuardContract $user)
{
$this->user = $user;
}
public function getSomeData()
{
$all = [];
$my = [...];
if ($this->user->isModerator()) {
$all = [...];
} else if ($this->user->isSuperadmin()) {
$all = [...];
}
return [$all, $my];
}
}
The getSomeData()
method looks ugly and it may be extended to other user roles.
Is there any design pattern to get a result depending on the user role? I am sure that strategy pattern
will look legit in this case.
Aucun commentaire:
Enregistrer un commentaire