/** * @param Request $request * @param Created $payload */ public function created(Request $request, Created $payload) { $serializer = Localization::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $document = new Document($resource); return new JsonResponse($document->toArray(), 201, ['Location' => $resource->getLinks()['self']]); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $serializer = LanguageVariant::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['localizations'])); $resource = $resource->fields($params->getFields(['language-variant' => LanguageVariant::getSerializer()->getFields(), 'localization' => Localization::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $serializer = Language::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['sublanguages', 'parent', 'scope', 'type', 'script', 'family', 'localizations'])); $resource = $resource->fields($params->getFields(['language' => Language::getSerializer()->getFields(), 'sublanguage' => Language::getSerializer()->getFields(), 'parent' => Language::getSerializer()->getFields(), 'scope' => LanguageScope::getSerializer()->getFields(), 'type' => LanguageType::getSerializer()->getFields(), 'script' => LanguageScript::getSerializer()->getFields(), 'family' => LanguageFamily::getSerializer()->getFields(), 'localization' => Localization::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Updated $payload */ public function updated(Request $request, Updated $payload) { $params = new Parameters($request->query->all()); $serializer = ApplicationUri::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['application', 'localization'])); $resource = $resource->fields($params->getFields(['application-uri' => ApplicationUri::getSerializer()->getFields(), 'application' => Application::getSerializer()->getFields(), 'localization' => Localization::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Updated $payload */ public function updated(Request $request, Updated $payload) { $params = new Parameters($request->query->all()); $serializer = Localization::getSerializer(); $resource = new Resource($payload->getModel(), $serializer); $resource = $resource->with($params->getInclude(['localizations', 'parent', 'language', 'ext-lang', 'script', 'language-variants', 'application-uris'])); $resource = $resource->fields($params->getFields(['localization' => Localization::getSerializer()->getFields(), 'parent' => Localization::getSerializer()->getFields(), 'language' => Language::getSerializer()->getFields(), 'ext-lang' => Language::getSerializer()->getFields(), 'script' => LanguageScript::getSerializer()->getFields(), 'language-variant' => LanguageVariant::getSerializer()->getFields(), 'application-uri' => ApplicationUri::getSerializer()->getFields()])); $document = new Document($resource); return new JsonResponse($document->toArray(), 200); }
/** * @param Request $request * @param Found $payload */ public function found(Request $request, Found $payload) { $params = new Parameters($request->query->all()); $data = $payload->getModel(); $serializer = ApplicationUri::getSerializer(); $resource = new Collection($data, $serializer); $resource = $resource->with($params->getInclude(['application', 'localization'])); $resource = $resource->fields($params->getFields(['application-uri' => ApplicationUri::getSerializer()->getFields(), 'application' => Application::getSerializer()->getFields(), 'localization' => Localization::getSerializer()->getFields()])); $document = new Document($resource); // meta if ($params->getPage('size') != -1) { $document->setMeta(['total' => $data->getNbResults(), 'first' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getFirstPage()]]), 'next' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getNextPage()]]), 'previous' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getPreviousPage()]]), 'last' => '%apiurl%/' . $serializer->getType(null) . '?' . $params->toQueryString(['page' => ['number' => $data->getLastPage()]])]); } // return response return new JsonResponse($document->toArray()); }
/** * @param Request $request * @param Found $payload */ public function read(Request $request, Found $payload) { $serializer = Localization::getSerializer(); $relationship = $serializer->parent($payload->getModel()); return new JsonResponse($relationship->toArray()); }
/** * @param mixed $model * @return Relationship */ public function parent($model) { $serializer = Localization::getSerializer(); $id = $serializer->getId($model->getParent()); if ($id !== null) { $relationship = new Relationship(new Resource($model->getParent(), $serializer)); $relationship->setLinks(['related' => '%apiurl%' . $serializer->getType(null) . '/' . $id]); return $this->addRelationshipSelfLink($relationship, $model, 'parent'); } return null; }
/** * @param Request $request * @param Updated $payload */ public function updated(Request $request, Updated $payload) { $serializer = Localization::getSerializer(); $relationship = $serializer->languageVariants($payload->getModel()); return new JsonResponse($relationship->toArray()); }
/** * Updates a Localization with the given idand the provided data * * @param mixed $id * @param mixed $data * @return PayloadInterface */ public function update($id, $data) { // find $model = $this->get($id); if ($model === null) { return new NotFound(['message' => 'Localization not found.']); } // hydrate $data = $this->normalize($data); $serializer = Localization::getSerializer(); $model = $serializer->hydrate($model, $data); $this->hydrateRelationships($model, $data); // dispatch pre save hooks $this->dispatch(LocalizationEvent::PRE_UPDATE, $model, $data); $this->dispatch(LocalizationEvent::PRE_SAVE, $model, $data); // validate $validator = $this->getValidator($model); if ($validator !== null && !$validator->validate($model)) { return new NotValid(['errors' => $validator->getValidationFailures()]); } // save and dispath post save hooks $rows = $model->save(); $this->dispatch(LocalizationEvent::POST_UPDATE, $model, $data); $this->dispatch(LocalizationEvent::POST_SAVE, $model, $data); $payload = ['model' => $model]; if ($rows === 0) { return new NotUpdated($payload); } return new Updated($payload); }