Scalr\Api\Service\User\V1beta0\Adapter\RoleAdapter::_scope PHP Method

_scope() protected method

protected _scope ( $from, $to, $action )
    protected function _scope($from, $to, $action)
    {
        if ($action == self::ACT_CONVERT_TO_OBJECT) {
            $to->scope = $from->getScope();
        } else {
            if ($action == self::ACT_CONVERT_TO_ENTITY) {
                if (empty($from->scope)) {
                    $from->scope = $this->controller->getScope();
                }
                switch ($from->scope) {
                    case ScopeInterface::SCOPE_SCALR:
                        $to->accountId = null;
                        $to->envId = null;
                        $to->origin = Entity\Role::ORIGIN_SHARED;
                        break;
                    case ScopeInterface::SCOPE_ACCOUNT:
                        $to->accountId = $this->controller->getUser()->accountId;
                        $to->envId = null;
                        $to->origin = Entity\Role::ORIGIN_CUSTOM;
                        break;
                    case ScopeInterface::SCOPE_ENVIRONMENT:
                        $to->accountId = $this->controller->getUser()->accountId;
                        $to->envId = $this->controller->getEnvironment()->id;
                        $to->origin = Entity\Role::ORIGIN_CUSTOM;
                        break;
                    default:
                        throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Unexpected scope value");
                }
            } else {
                if ($action == self::ACT_GET_FILTER_CRITERIA) {
                    if (empty($from->scope)) {
                        throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Invalid scope value");
                    }
                    if ($from->scope === ScopeInterface::SCOPE_SCALR) {
                        return [['accountId' => null], ['envId' => null]];
                    } else {
                        if ($from->scope === ScopeInterface::SCOPE_ACCOUNT) {
                            return [['accountId' => $this->controller->getUser()->accountId], ['envId' => null]];
                        } else {
                            if ($from->scope === ScopeInterface::SCOPE_ENVIRONMENT && $this->controller->getEnvironment() !== null) {
                                return [['envId' => $this->controller->getEnvironment()->id]];
                            } else {
                                throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, "Unexpected scope value");
                            }
                        }
                    }
                }
            }
        }
    }