public function format(Account $account, array $frontline) { $profiles = array_map(function (Profile $profile) { return $this->profileFormatter->format($profile); }, $account->getProfiles()->toArray()); return ["api_key" => $account->getAPIKey(), "account" => $account->toJSON(), "profiles" => $profiles, "frontline" => $frontline]; }
public function validateIsProfileOwnedByAccount(Account $account, Profile $profile) : self { if (!$account->getProfiles()->contains($profile)) { throw new PermissionsDeniedException("You're not an owner of this profile"); } return $this; }
public function createProfileForAccount(Account $account) : Profile { if ($account->getProfiles()->count() >= self::MAX_PROFILES_PER_ACCOUNT) { throw new MaxProfilesReachedException(sprintf('You can only have %d profiles per account', self::MAX_PROFILES_PER_ACCOUNT)); } $account->getProfiles()->add($profile = new Profile($account)); $this->profileRepository->createProfile($profile); $this->accountService->switchToProfile($account, $profile->getId()); $this->generateProfileImage($profile->getId()); $this->backdropService->backdropPreset($profile, $this->backdropPresetFactory, $this->backdropPresetFactory->getListIds()[array_rand($this->backdropPresetFactory->getListIds())]); $this->getEventEmitter()->emit(self::EVENT_PROFILE_CREATED, [$profile]); return $profile; }
public function switchToProfile(Account $account, int $switchToProfileId) : Account { if (!$account->getProfiles()->filter(function (Profile $profile) use($switchToProfileId) { return $profile->getId() === $switchToProfileId; })->count()) { throw new AccountNotContainsProfileException(sprintf('Profile (ID: %s) is not exists', $switchToProfileId)); } $account->getProfiles()->map(function (Profile $profile) use($switchToProfileId, &$found) { $profile->getId() === $switchToProfileId ? $profile->setAsCurrent() : $profile->unsetAsCurrent(); }); $this->accountRepository->saveAccount($account); array_map(function (Profile $profile) { $this->profileRepository->saveProfile($profile); }, $account->getProfiles()->toArray()); return $account; }