/**
  * @param Attachment $attachment
  * @param array      $dimensionIds
  *
  * @return ImageInstance
  */
 public function create(Attachment $attachment, DimensionContainer $dimensionContainer)
 {
     $validate = $this->constraints->getConstraints($attachment, $dimensionContainer);
     if ($validate) {
         $fs = new Filesystem();
         $fs->remove(sprintf('%s/%s', $this->tempPath, $attachment->getFile()));
         $fs->remove(sprintf('%s/%s', $this->uploadPath, $attachment->getFile()));
         $this->objectManager->remove($attachment);
         $this->objectManager->flush();
         return $validate;
     }
     $instance = new ImageInstance();
     $instance->setName($attachment->getName());
     $this->objectManager->persist($instance);
     foreach ($dimensionContainer->getDimensions() as $dimension) {
         $cropping = new ImageCropping();
         $cropping->setAttachment($attachment);
         $cropping->setInstance($instance);
         $cropping->setDimension($dimension);
         $cropping->setName($attachment->getName());
         $this->objectManager->persist($cropping);
     }
     $this->objectManager->flush();
     return $instance;
 }