Lemon\RestBundle\Object\IdHelper::setId PHP Method

setId() public static method

public static setId ( object $object, integer $id )
$object object
$id integer
    public static function setId($object, $id)
    {
        self::getIdProperty($object)->setValue($object, $id);
    }

Usage Example

Example #1
0
 /**
  * @param object $object
  */
 public function processIds($object)
 {
     $id = IdHelper::getId($object);
     if ($id !== null && empty($id)) {
         IdHelper::setId($object, null);
     }
     $class = get_class($object);
     $reflection = new \ReflectionClass($class);
     $em = $this->doctrine->getManagerForClass($class);
     /** @var \Doctrine\Common\Persistence\Mapping\ClassMetadata $metadata */
     $metadata = $em->getMetadataFactory()->getMetadataFor($class);
     // Look for relationships, compare against preloaded entity
     foreach ($metadata->getAssociationNames() as $fieldName) {
         $property = $reflection->getProperty($fieldName);
         $property->setAccessible(true);
         $value = $property->getValue($object);
         if (!$value) {
             continue;
         }
         if ($metadata->isCollectionValuedAssociation($fieldName)) {
             foreach ($value as $v) {
                 $this->processIds($v);
             }
         }
     }
 }
All Usage Examples Of Lemon\RestBundle\Object\IdHelper::setId