22namespace AppVentus \Awesome \SpoolMailerBundle \Utils ;
33
44use AppVentus \Awesome \SpoolMailerBundle \Entity \Attachment ;
5- use Doctrine \Bundle \ DoctrineBundle \ Registry as DoctrineRegistry ;
5+ use Doctrine \ORM \ EntityManager ;
66use Gedmo \Exception \UploadableDirectoryNotFoundException ;
7- use Swift_FileStream ;
87
98/**
109 * Class AttachmentUploader
@@ -15,31 +14,29 @@ class AttachmentUploader {
1514
1615 private $ targetDir ;
1716 private $ rootDir ;
18- private $ em ;
1917
2018 /**
2119 * AttachmentUploader constructor.
2220 *
2321 * @param $targetDir
2422 * @param $rootDir
25- * @param \Doctrine\Bundle\DoctrineBundle\Registry $registry
2623 */
27- public function __construct ($ targetDir , $ rootDir, DoctrineRegistry $ registry )
24+ public function __construct ($ targetDir , $ rootDir )
2825 {
2926 $ this ->targetDir = $ targetDir ;
3027 $ this ->rootDir = $ rootDir ;
31- $ this ->em = $ registry ->getManager ();
3228 }
3329
3430 /**
3531 * @param \AppVentus\Awesome\SpoolMailerBundle\Entity\Attachment $attachment
32+ * @param EntityManager $em
3633 */
37- public function upload (Attachment $ attachment )
34+ public function upload (Attachment $ attachment, EntityManager $ em )
3835 {
3936 if ($ swiftAttachment = $ attachment ->getSwiftAttachment ())
4037 {
4138 /** @var Attachment $duplicatedAttachment */
42- $ duplicatedAttachment = $ this -> em ->getRepository (Attachment::class)->findOneBy (['swiftAttachmentId ' => $ attachment ->getSwiftAttachmentId ()]);
39+ $ duplicatedAttachment = $ em ->getRepository (Attachment::class)->findOneBy (['swiftAttachmentId ' => $ attachment ->getSwiftAttachmentId ()]);
4340 if (!$ duplicatedAttachment )
4441 {
4542 $ fileName = md5 (uniqid ('' , true )).'_ ' .$ swiftAttachment ->getFilename ();
0 commit comments