/** * @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; }
/** * @return mixed */ public function current() { return $this->response->withItem($this->context->user(), new UserTransformer()); }
public function testHasNoUser() { $context = new Context(); $this->assertFalse($context->hasUser()); $this->assertNull($context->user()); }