/** * @param User $user * @throws \InvalidArgumentException if user isn't valid * @throws \DomainException if username is taken */ public function create(User $user) { if (!$user->isValid()) { throw new \InvalidArgumentException('User is not valid'); } if ($this->getByUsername($user->getUsername())) { throw new \DomainException('Username is taken'); } $this->database->insert($user); }
/** * @param User $user */ public function login(User $user) { $this->user = $user; $this->setSession($user->getUsername()); }