/** * @param $id * @param User $user * @return bool * This function check if the Id passed in first parameter is equal to the id of the second * Admin is an exception */ public function sameUser($id, $user) { if ($user->hasRole('ROLE_ADMIN')) { return true; } else { if ($id == $user->getId()) { return true; } else { throw new HttpException(403, 'forbidden !'); } } }
/** * {@inheritDoc} */ public function hasRole($role) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'hasRole', [$role]); return parent::hasRole($role); }
/** * @dataProvider userProvider */ public function testUpdateRole(User $user, $role, $active) { $user->updateRole($role, $active); $this->assertEquals($active, $user->hasRole($role)); }