getId() public static method

public static getId ( object $object ) : mixed
$object object
return mixed
コード例 #1
0
 /**
  * @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;
 }
コード例 #2
0
 /**
  * @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;
     });
 }
コード例 #3
0
ファイル: Processor.php プロジェクト: stanlemon/rest-bundle
 /**
  * @param object $object
  * @return bool
  */
 protected function isNew($object)
 {
     return IdHelper::getId($object) === null;
 }
コード例 #4
0
ファイル: Manager.php プロジェクト: stanlemon/rest-bundle
 /**
  * @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;
 }
コード例 #5
0
 /**
  * @covers ::getId
  */
 public function testGetId()
 {
     $person = new Person();
     $person->id = 1;
     $this->assertEquals($person->id, IdHelper::getId($person));
 }