/** * @param $attribute * @param $value * @param $parameters * @return bool */ public function validate($attribute, $value, $parameters) { //If the email already exist in the account, the validation must fail !! if ($this->userRepository->isEmailExistForThisAccount($this->context->account(), $value)) { return false; } return true; }
/** * @return User */ public function resolve() { //Get the user from context $user = $this->context->user(); //If user found in context if (!empty($user)) { return $user; } //Else no user found in context, so create a guest user instance $guestUser = new User(); $guestUser->role = User::GUEST_ROLE; //If account exist in context, just add account id to the guest user if ($this->context->account()) { $guestUser->account_id = $this->context->account()->id; } return $guestUser; }
/** * Set application locale based on context. * We doing this here because it's simpler than create a middleware just for this * and the application locale is strongly bind to the current context */ private function setApplicationLocale() { //If we have a user in context, the user locale prevail the account local if ($this->context->hasUser()) { //Set the local from user $this->setLocaleFromUser($this->context->user()); return; } //If we have account, set the locale from account if ($this->context->hasAccount()) { $this->setLocaleFromAccount($this->context->account()); } return; }
public function testHasNoAccount() { $context = new Context(); $this->assertFalse($context->hasAccount()); $this->assertNull($context->account()); }