2
2
3
3
namespace Sherlockode \AdvancedFormBundle \Manager ;
4
4
5
- use Doctrine \Common \ Persistence \ ObjectManager ;
5
+ use Doctrine \ORM \ EntityManagerInterface ;
6
6
use Sherlockode \AdvancedFormBundle \Event \RemoveUploadEvent ;
7
7
use Sherlockode \AdvancedFormBundle \Event \UploadEvent ;
8
8
use Sherlockode \AdvancedFormBundle \Model \TemporaryUploadedFileInterface ;
15
15
class UploadManager
16
16
{
17
17
/**
18
- * @var ObjectManager
18
+ * @var EntityManagerInterface
19
19
*/
20
- private $ om ;
20
+ private $ em ;
21
21
22
22
/**
23
23
* @var MappingManager
@@ -44,20 +44,20 @@ class UploadManager
44
44
/**
45
45
* UploadManager constructor.
46
46
*
47
- * @param ObjectManager $om
47
+ * @param EntityManagerInterface $em
48
48
* @param MappingManager $mappingManager
49
49
* @param EventDispatcherInterface $eventDispatcher
50
50
* @param StorageInterface $tmpStorage
51
51
* @param string|null $tmpUploadedFileClass
52
52
*/
53
53
public function __construct (
54
- ObjectManager $ om ,
54
+ EntityManagerInterface $ em ,
55
55
MappingManager $ mappingManager ,
56
56
EventDispatcherInterface $ eventDispatcher ,
57
57
StorageInterface $ tmpStorage ,
58
58
$ tmpUploadedFileClass = null
59
59
) {
60
- $ this ->om = $ om ;
60
+ $ this ->em = $ em ;
61
61
$ this ->mappingManager = $ mappingManager ;
62
62
$ this ->eventDispatcher = $ eventDispatcher ;
63
63
$ this ->tmpStorage = $ tmpStorage ;
@@ -87,7 +87,7 @@ public function upload(UploadedFile $uploadedFile, $type, $id = null)
87
87
if ($ id === null ) {
88
88
$ subject = new $ entityClass ();
89
89
} else {
90
- $ subject = $ this ->om ->getRepository ($ entityClass )->find ($ id );
90
+ $ subject = $ this ->em ->getRepository ($ entityClass )->find ($ id );
91
91
if (null === $ subject ) {
92
92
throw new \Exception (sprintf ('Cannot find object of type "%s" with id %s. ' , $ type , $ id ));
93
93
}
@@ -108,8 +108,8 @@ public function upload(UploadedFile $uploadedFile, $type, $id = null)
108
108
$ handler ->upload ($ subject , $ mapping ->fileProperty , $ uploadedFile );
109
109
$ this ->eventDispatcher ->dispatch ('afb.post_upload ' , new UploadEvent ($ subject , $ mapping , $ uploadedFile ));
110
110
111
- $ this ->om ->persist ($ subject );
112
- $ this ->om ->flush ();
111
+ $ this ->em ->persist ($ subject );
112
+ $ this ->em ->flush ();
113
113
114
114
return $ subject ;
115
115
}
@@ -135,8 +135,8 @@ public function uploadTemporary(UploadedFile $uploadedFile)
135
135
$ obj ->setToken (rand ());
136
136
$ obj ->setFilename ($ uploadedFile ->getClientOriginalName ());
137
137
138
- $ this ->om ->persist ($ obj );
139
- $ this ->om ->flush ($ obj );
138
+ $ this ->em ->persist ($ obj );
139
+ $ this ->em ->flush ($ obj );
140
140
141
141
return $ obj ;
142
142
}
@@ -147,8 +147,8 @@ public function uploadTemporary(UploadedFile $uploadedFile)
147
147
public function removeTemporary (TemporaryUploadedFileInterface $ fileInfo )
148
148
{
149
149
$ 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 );
152
152
}
153
153
154
154
/**
@@ -162,7 +162,7 @@ public function remove($type, $id, $deleteObject = false)
162
162
{
163
163
if (null !== $ type && null !== $ id ) {
164
164
$ mapping = $ this ->mappingManager ->getMapping ($ type );
165
- $ subject = $ this ->om ->getRepository ($ mapping ->fileClass )->find ($ id );
165
+ $ subject = $ this ->em ->getRepository ($ mapping ->fileClass )->find ($ id );
166
166
if (null === $ subject ) {
167
167
throw new \Exception (sprintf ('Cannot find object of type "%s" with id %s. ' , $ type , $ id ));
168
168
}
@@ -171,9 +171,9 @@ public function remove($type, $id, $deleteObject = false)
171
171
$ handler ->remove ($ subject , $ field );
172
172
$ this ->eventDispatcher ->dispatch ('afb.post_remove_upload ' , new RemoveUploadEvent ($ subject , $ mapping ));
173
173
if ($ deleteObject || $ mapping ->multiple ) {
174
- $ this ->om ->remove ($ subject );
174
+ $ this ->em ->remove ($ subject );
175
175
}
176
- $ this ->om ->flush ();
176
+ $ this ->em ->flush ();
177
177
}
178
178
}
179
179
0 commit comments