Load the user's roles on the project's environments.

@param \Platformsh\Client\Model\ProjectAccess $projectAccess

@return array
186715
private function getEnvironmentRoles(ProjectAccess $projectAccess)
    {
        $environmentRoles = [];
        if ($projectAccess->role === ProjectAccess::ROLE_ADMIN) {
            return [];
        }

        // @todo find out why $environment->getUser() has permission issues - it would be a lot faster than this

        $progress = new ProgressBar(isset($this->stdErr) && $this->stdErr->isDecorated() ? $this->stdErr : new NullOutput());
        $progress->setMessage('Loading environments...');
        $progress->setFormat('%message% %current%/%max%');
        $environments = $this->api()->getEnvironments($this->getSelectedProject());
        $progress->start(count($environments));
        foreach ($environments as $environment) {
            if ($access = $environment->getUser($projectAccess->id)) {
                $environmentRoles[$environment->id] = $access->role;
            }
            $progress->advance();
        }
        $progress->finish();
        $progress->clear();

        return $environmentRoles;
    }
278988
public function collectRelativeRoles(Site $context = null)
    {
        $event = new RolesCollectionEvent($this->getDefaultRelativeRoles(), $context);
        $this->dispatcher->dispatch(RolesCollectionEvent::EVENT_NAME, $event);
        return $event->getRoles();
    }
525191
public function getAccessibleRoles(array $roles)
    {
        $accessibleRoles = $roles;
        foreach ($roles as $role) {
            /**
             * @var $role Role
             */
            if (isset($this->map[$role->getRole()])) {
                foreach ($this->map[$role->getRole()] as $r) {
                    $accessibleRoles[] = new Role($r);
                }
            }
        }

        return $accessibleRoles;
    }
599954
protected function getAccessors(array $fields = null)
    {
        $accessors = [];

        foreach ($fields as $field) {
            if ($field->isMultipleAnswers()) {
                $content = $this->getStubContent('model-accessor-multiple-answers');

                $accessors[] = $this->getAccessor($field, $content);
            }

            if ($field->isDateOrTime()) {
                $content = $this->getStubContent('model-accessor-datetime');
                $this->replaceDateFormat($content, $field->dateFormat);

                $accessors[] = $this->getAccessor($field, $content);
            }
        }

        return implode(PHP_EOL, $accessors);
    }
192015
private function getRestrictedLanguagesCodes($hasAccess): array
    {
        if (!\is_array($hasAccess)) {
            return [];
        }

        $restrictedLanguagesCodes = $this->permissionChecker->getRestrictions($hasAccess, LanguageLimitation::class);

        if (empty($restrictedLanguagesCodes)) {
            return [];
        }

        return $restrictedLanguagesCodes;
    }
121086
private function getUserRolesAsObjects(UserInterface $user)
    {
        $userRoles = array();
        foreach ($user->getRoles() as $userRole) {
            $userRoles[] = $userRole instanceof Role ? $userRole : new Role($userRole);
        }

        return $userRoles;
    }
1261897
private function loadPermissions(array $sids)
    {
        $roles = IdentityUtils::filterRolesIdentities($sids);
        $id = implode('|', $roles);

        if (!\array_key_exists($id, $this->cache)) {
            $this->cache[$id] = [];
            $preEvent = new PreLoadPermissionsEvent($sids, $roles);
            $this->dispatcher->dispatch(PermissionEvents::PRE_LOAD, $preEvent);
            $perms = $this->provider->getPermissions($roles);

            $this->buildSystemPermissions($id);

            foreach ($perms as $perm) {
                $class = PermissionUtils::getMapAction($perm->getClass());
                $field = PermissionUtils::getMapAction($perm->getField());
                $this->cache[$id][$class][$field][$perm->getOperation()] = true;
            }

            $postEvent = new PostLoadPermissionsEvent($sids, $roles, $this->cache[$id]);
            $this->dispatcher->dispatch(PermissionEvents::POST_LOAD, $postEvent);
            $this->cache[$id] = $postEvent->getPermissionMap();
        }

        return $id;
    }
852691
public function getSiteAccesses($mandatorId = null, $siteAccess = null)
    {
        if ($mandatorId) {
            $siteAccesses = $this->getSiteaccessesByMandatorId($mandatorId);
        } elseif ($siteAccess) {
            $siteAccesses = array($siteAccess);
        } else {
            $siteAccesses = array($this->siteAccess->name);
        }

        return $siteAccesses;
    }
745428
protected function getImageVariationsForSiteaccess($siteaccess)
    {
        $variations = [];
        $imageAliasesList = $this->getGroup('AliasSettings', 'image.ini', $siteaccess);
        foreach ($imageAliasesList['AliasList'] as $imageAliasIdentifier) {
            $variationSettings = ['reference' => null, 'filters' => []];
            $aliasSettings = $this->getGroup($imageAliasIdentifier, 'image.ini', $siteaccess);
            if (isset($aliasSettings['Reference']) && $aliasSettings['Reference'] != '') {
                $variationSettings['reference'] = $aliasSettings['Reference'];
            }
            if (isset($aliasSettings['Filters']) && \is_array($aliasSettings['Filters'])) {
                // parse filters. Format: filtername=param1;param2...paramN
                foreach ($aliasSettings['Filters'] as $filterString) {
                    $filteringSettings = [];

                    if (strstr($filterString, '=') !== false) {
                        list($filteringSettings['name'], $filterParams) = explode('=', $filterString);
                        $filterParams = explode(';', $filterParams);

                        // make sure integers are actually integers, not strings
                        array_walk(
                            $filterParams,
                            static function (&$value) {
                                if (preg_match('/^[0-9]+$/', $value)) {
                                    $value = (int)$value;
                                }
                            }
                        );

                        $filteringSettings['params'] = $filterParams;
                    } else {
                        $filteringSettings['name'] = $filterString;
                    }

                    $variationSettings['filters'][] = $filteringSettings;
                }
            }
            $variations[$imageAliasIdentifier] = $variationSettings;
        }

        return $variations;
    }
544790
private function getRestrictedContentTypes(array $hasAccess): array
    {
        $restrictedContentTypesIds = $this->permissionChecker->getRestrictions($hasAccess, ContentTypeLimitation::class);
        if (empty($restrictedContentTypesIds)) {
            return [];
        }

        $restrictedContentTypesIdentifiers = [];
        $restrictedContentTypes = $this->contentTypeService->loadContentTypeList($restrictedContentTypesIds);
        foreach ($restrictedContentTypes as $restrictedContentType) {
            $restrictedContentTypesIdentifiers[] = $restrictedContentType->identifier;
        }

        return $restrictedContentTypesIdentifiers;
    }
801179
public function getterRoleConstants(): array
	{
		$result = [];
		$roles = $this->roles->get();
		/* @var $role AclRole */
		foreach ($roles as $role) {
			$result[] = $role->name;
		}
		return $result;
	}
276113
public static function getServerListByRoles(array $roles)
    {
        $servers = [];
        foreach ($roles as $roleCode) {
            $rolesForCode = RoleManager::getServersByRole($roleCode);

            foreach ($rolesForCode as $serverCode) {
                if (in_array($serverCode, $servers, true)) {
                    continue;
                }

                $servers[] = $serverCode;
            }
        }

        return $servers;
    }
296961
public function getRoles()
    {
        $roles = array();
        foreach ($this->groups as $group) {
            $roles[] = $group->getAsRole();
        }
        $roles[] = 'ROLE_USER';
        return $roles;
    }
81079
public function getAccessListItems($accessType = PermissionKey::ACCESS_TYPE_INCLUDE, $filterEntities = [], $checkCache = true)
    {
        if (count($this->paIDList) > 0) {
            $q = 'select paID, peID, pdID, accessType from PermissionAccessList where paID in (' . implode(',', $this->paIDList) . ')';

            return $this->deliverAccessListItems($q, $accessType, $filterEntities);
        }
        // Sometimes we want to disable cache checking here because we're going to be
        // adding items to the cache from a class that subclasses this one. See
        // AddBlockToAreaAreaAccess
        if ($checkCache) {
            $app = Application::getFacadeApplication();
            $cache = $app->make('cache/request');
            $item = $cache->getItem($this->getCacheIdentifier($accessType, $filterEntities));
            if (!$item->isMiss()) {
                return $item->get();
            }
            $item->lock();
        }

        $q = 'select paID, peID, pdID, accessType from PermissionAccessList where paID = ' . $this->getPermissionAccessID();
        $items = $this->deliverAccessListItems($q, $accessType, $filterEntities);

        if ($checkCache) {
            $cache->save($item->set($items));
        }

        return $items;
    }
942099
public function grantAccessByRoles($roles, UserInterface $user = null)
    {
        $user = $user ? : $this->currentUser();
        return count(array_diff($roles, $user->getRoles())) === 0;
    }
60728
private function getSpecifiedProjectRole(array $roles)
    {
        foreach ($roles as $role) {
            if (strpos($role, ':') === false) {
                return $this->validateProjectRole($role);
            }
        }

        return null;
    }
338472
private function getUserLabel(ProjectAccess $access)
    {
        $account = $this->api()->getAccount($access);

        return sprintf('<info>%s</info> (%s)', $account['display_name'], $account['email']);
    }