repository = $repository; $this->roles = $roles; $this->transaction = $transaction; //$this->newsletter = $newsletter; } public function create(UserForm $form): User { $user = User::create( $form->username, $form->email, $form->password ); $this->transaction->wrap(function () use ($user, $form) { $this->repository->save($user); $this->roles->assign($user->id, $form->role); //$this->newsletter->subscribe($user->email); }); return $user; } public function edit($id, UserForm $form): void { $user = $this->repository->get($id); $user->edit( $form->username, $form->email, $form->password ); $this->transaction->wrap(function () use ($user, $form) { $this->repository->save($user); $this->roles->assign($user->id, $form->role); }); } public function assignRole($id, $role): void { $user = $this->repository->get($id); $this->roles->assign($user->id, $role); } public function remove($id): void { $user = $this->repository->get($id); $this->repository->remove($user); //$this->newsletter->unsubscribe($user->email); } }