/** * @param JsonSerializationVisitor $visitor * @param Collection $idCollection * @param array $type * @param Context $context * @return array */ public function serializeIdCollectionToJson(JsonSerializationVisitor $visitor, Collection $idCollection, array $type, Context $context) { $ids = array(); foreach ($idCollection as $id) { $ids[] = IdHelper::getId($id); } return $ids; }
/** * @param Request $request * @param string $resource * @return Response */ public function postAction(Request $request, $resource) { $response = $this->response; $router = $this->router; return $this->handler->handle($request, $this->response, $resource, function (ManagerInterface $manager, $object) use($response, $resource, $router) { $manager->create($object); $response->setStatusCode(201); $response->headers->set('Location', $router->generate('lemon_rest_get', array('resource' => $resource, 'id' => IdHelper::getId($object)), RouterInterface::ABSOLUTE_URL)); return $object; }); }
/** * @param object $object * @return bool */ protected function isNew($object) { return IdHelper::getId($object) === null; }
/** * @param object $object * @return object */ public function update($object) { !$this->objectDefinition->canUpdate() && $this->throwUnsupportedMethodException(); $em = $this->getManager(); $original = $this->retrieve(IdHelper::getId($object)); $this->eventDispatcher->dispatch(RestEvents::PRE_UPDATE, new ObjectEvent($object, $original)); $object = $em->merge($object); $em->persist($object); $em->flush(); $em->refresh($object); $this->eventDispatcher->dispatch(RestEvents::POST_UPDATE, new ObjectEvent($object, $original)); return $object; }
/** * @covers ::getId */ public function testGetId() { $person = new Person(); $person->id = 1; $this->assertEquals($person->id, IdHelper::getId($person)); }