/** * Automatically generated run method * * @param Request $request * @return Response */ public function run(Request $request) { $sport = SportQuery::create()->findOneById($this->getParam('id')); $object = new Object(); $object->setSport($sport); $data = ['sport' => $sport, 'object' => $object]; $payload = new Blank($data); if ($request->isMethod('POST')) { $post = $request->request; $domain = new ObjectDomain($this->getServiceContainer()); $serializer = Object::getSerializer(); $fields = $serializer->getFields(); $attribs = []; foreach ($fields as $field) { if ($post->has($field)) { $attribs[$field] = $post->get($field); } } $attribs['fixed'] = $post->has('fixed'); $payload = $domain->create(['attributes' => $attribs, 'relationships' => ['sport' => ['data' => ['id' => $sport->getId()]]]]); if ($payload instanceof NotValid) { $payload = new NotValid(array_merge($data, $payload->get())); } } return $this->responder->run($request, $payload); }
/** * Automatically generated run method * * @param Request $request * @return Response */ public function run(Request $request) { $body = Json::decode($request->getContent()); if (!isset($body['data'])) { throw new InvalidParameterException(); } $data = $body['data']; $domain = new ObjectDomain($this->getServiceContainer()); $payload = $domain->create($data); return $this->responder->run($request, $payload); }