parseId($args['id']); $range = $this->getRange($rangeId); if (!Authority::canEditConfigValue($this->getUser($request), $range)) { throw new AuthorizationFailedException(); } $resource = $this->findOrFakeConfigValue($range, $field); // TODO: zunächst kann diese Route nur Konfigurationseinstellungen vom Typ bool ändern if ( 'boolean' !== $resource->entry['type'] && $resource->entry['field'] !== 'CONTENTMODULES_TILED_DISPLAY' && $resource->entry['field'] !== 'MY_COURSES_OPEN_GROUPS' && $resource->entry['field'] !== 'MY_COURSES_VIEW_SETTINGS' ) { throw new NotImplementedException(); } $json = $this->validate($request, $resource); $resource = $this->updateConfigValue($resource, $json); return $this->getContentResponse($resource); } protected function validateResourceDocument($json, $data) { if (!self::arrayHas($json, 'data')) { return 'Missing `data` member at document´s top level.'; } if (ConfigValueSchema::TYPE !== self::arrayGet($json, 'data.type')) { return 'Wrong `type` member of document´s `data`.'; } if (!self::arrayHas($json, 'data.id')) { return 'Document must have an `id`.'; } if (self::arrayGet($json, 'data.id') !== $this->generateId($data)) { return 'Mismatch between URI parameter and document `id`.'; } if (!self::arrayHas($json, 'data.attributes.value')) { return 'The attribute `value` must exist.'; } } private function updateConfigValue(\ConfigValue $resource, array $json): \ConfigValue { if (!($config = $resource->getConfigObject())) { throw new InvalidArgumentException('Invalid configuration object.'); } $config->store($resource['field'], self::arrayGet($json, 'data.attributes.value')); return $resource; } }