Kdyby\Doctrine\EntityManager::persist PHP Method

persist() public method

public persist ( object | array $entity ) : EntityManager
$entity object | array
return EntityManager
    public function persist($entity)
    {
        foreach (is_array($entity) ? $entity : func_get_args() as $item) {
            parent::persist($item);
        }
        return $this;
    }

Usage Example

Beispiel #1
0
 /**
  * @param FileUpload $file
  * @return Image
  * @throws NotImageUploadedException
  * @throws FileSizeException
  * @throws DBALException
  * @throws InvalidStateException
  */
 public function processImage(FileUpload $file)
 {
     if (!$file->isImage()) {
         throw new NotImageUploadedException();
     }
     if (\filesize($file->getTemporaryFile()) > Image::MAX_FILE_SIZE) {
         throw new FileSizeException();
     }
     try {
         $this->em->beginTransaction();
         $image = new Image($file);
         $this->em->persist($image)->flush();
         $file->move($this->composeImageLocation($image));
         $this->em->commit();
     } catch (InvalidStateException $is) {
         $this->em->rollback();
         $this->em->close();
         $this->logger->addError('Error occurs while moving temp. image file to new location.');
         throw $is;
     } catch (DBALException $e) {
         $this->em->rollback();
         $this->em->close();
         $this->logger->addError('Image error');
         // todo err message
         throw $e;
     }
     return $image;
 }
All Usage Examples Of Kdyby\Doctrine\EntityManager::persist