22
33namespace Sherlockode \AdvancedFormBundle \Manager ;
44
5- use Doctrine \Common \ Persistence \ ObjectManager ;
5+ use Doctrine \ORM \ EntityManagerInterface ;
66use Sherlockode \AdvancedFormBundle \Event \RemoveUploadEvent ;
77use Sherlockode \AdvancedFormBundle \Event \UploadEvent ;
88use Sherlockode \AdvancedFormBundle \Model \TemporaryUploadedFileInterface ;
1515class UploadManager
1616{
1717 /**
18- * @var ObjectManager
18+ * @var EntityManagerInterface
1919 */
20- private $ om ;
20+ private $ em ;
2121
2222 /**
2323 * @var MappingManager
@@ -44,20 +44,20 @@ class UploadManager
4444 /**
4545 * UploadManager constructor.
4646 *
47- * @param ObjectManager $om
47+ * @param EntityManagerInterface $em
4848 * @param MappingManager $mappingManager
4949 * @param EventDispatcherInterface $eventDispatcher
5050 * @param StorageInterface $tmpStorage
5151 * @param string|null $tmpUploadedFileClass
5252 */
5353 public function __construct (
54- ObjectManager $ om ,
54+ EntityManagerInterface $ em ,
5555 MappingManager $ mappingManager ,
5656 EventDispatcherInterface $ eventDispatcher ,
5757 StorageInterface $ tmpStorage ,
5858 $ tmpUploadedFileClass = null
5959 ) {
60- $ this ->om = $ om ;
60+ $ this ->em = $ em ;
6161 $ this ->mappingManager = $ mappingManager ;
6262 $ this ->eventDispatcher = $ eventDispatcher ;
6363 $ this ->tmpStorage = $ tmpStorage ;
@@ -87,7 +87,7 @@ public function upload(UploadedFile $uploadedFile, $type, $id = null)
8787 if ($ id === null ) {
8888 $ subject = new $ entityClass ();
8989 } else {
90- $ subject = $ this ->om ->getRepository ($ entityClass )->find ($ id );
90+ $ subject = $ this ->em ->getRepository ($ entityClass )->find ($ id );
9191 if (null === $ subject ) {
9292 throw new \Exception (sprintf ('Cannot find object of type "%s" with id %s. ' , $ type , $ id ));
9393 }
@@ -108,8 +108,8 @@ public function upload(UploadedFile $uploadedFile, $type, $id = null)
108108 $ handler ->upload ($ subject , $ mapping ->fileProperty , $ uploadedFile );
109109 $ this ->eventDispatcher ->dispatch ('afb.post_upload ' , new UploadEvent ($ subject , $ mapping , $ uploadedFile ));
110110
111- $ this ->om ->persist ($ subject );
112- $ this ->om ->flush ();
111+ $ this ->em ->persist ($ subject );
112+ $ this ->em ->flush ();
113113
114114 return $ subject ;
115115 }
@@ -135,8 +135,8 @@ public function uploadTemporary(UploadedFile $uploadedFile)
135135 $ obj ->setToken (rand ());
136136 $ obj ->setFilename ($ uploadedFile ->getClientOriginalName ());
137137
138- $ this ->om ->persist ($ obj );
139- $ this ->om ->flush ($ obj );
138+ $ this ->em ->persist ($ obj );
139+ $ this ->em ->flush ($ obj );
140140
141141 return $ obj ;
142142 }
@@ -147,8 +147,8 @@ public function uploadTemporary(UploadedFile $uploadedFile)
147147 public function removeTemporary (TemporaryUploadedFileInterface $ fileInfo )
148148 {
149149 $ this ->tmpStorage ->remove ($ fileInfo ->getKey ());
150- $ this ->om ->remove ($ fileInfo );
151- $ this ->om ->flush ($ fileInfo );
150+ $ this ->em ->remove ($ fileInfo );
151+ $ this ->em ->flush ($ fileInfo );
152152 }
153153
154154 /**
@@ -162,7 +162,7 @@ public function remove($type, $id, $deleteObject = false)
162162 {
163163 if (null !== $ type && null !== $ id ) {
164164 $ mapping = $ this ->mappingManager ->getMapping ($ type );
165- $ subject = $ this ->om ->getRepository ($ mapping ->fileClass )->find ($ id );
165+ $ subject = $ this ->em ->getRepository ($ mapping ->fileClass )->find ($ id );
166166 if (null === $ subject ) {
167167 throw new \Exception (sprintf ('Cannot find object of type "%s" with id %s. ' , $ type , $ id ));
168168 }
@@ -171,9 +171,9 @@ public function remove($type, $id, $deleteObject = false)
171171 $ handler ->remove ($ subject , $ field );
172172 $ this ->eventDispatcher ->dispatch ('afb.post_remove_upload ' , new RemoveUploadEvent ($ subject , $ mapping ));
173173 if ($ deleteObject || $ mapping ->multiple ) {
174- $ this ->om ->remove ($ subject );
174+ $ this ->em ->remove ($ subject );
175175 }
176- $ this ->om ->flush ();
176+ $ this ->em ->flush ();
177177 }
178178 }
179179
0 commit comments