1
1
<?php
2
- declare (strict_types= 1 );
2
+ declare (strict_types = 1 );
3
3
4
4
namespace Burzum \FileStorage \Model \Behavior ;
5
5
@@ -54,7 +54,7 @@ class FileStorageBehavior extends Behavior
54
54
'ignoreEmptyFile ' => true ,
55
55
'fileField ' => 'file ' ,
56
56
'fileStorage ' => null ,
57
- 'imageProcessor ' => null
57
+ 'imageProcessor ' => null ,
58
58
];
59
59
60
60
/**
@@ -64,17 +64,19 @@ class FileStorageBehavior extends Behavior
64
64
65
65
/**
66
66
* @inheritDoc
67
+ *
68
+ * @throws \RuntimeException
67
69
*/
68
70
public function initialize (array $ config ): void
69
71
{
70
72
parent ::initialize ($ config );
71
73
72
- if ($ this ->getConfig ('fileStorage ' ) instanceOf FileStorage) {
74
+ if ($ this ->getConfig ('fileStorage ' ) instanceof FileStorage) {
73
75
$ this ->fileStorage = $ this ->getConfig ('fileStorage ' );
74
76
} else {
75
- throw new RuntimeException (
77
+ throw new RuntimeException (
76
78
'Missing or invalid fileStorage config key '
77
- );
79
+ );
78
80
}
79
81
80
82
if (!$ this ->getConfig ('dataTransformer ' ) instanceof DataTransformerInterface) {
@@ -85,8 +87,8 @@ public function initialize(array $config): void
85
87
}
86
88
87
89
/**
88
- * @throws \InvalidArgumentException
89
90
* @param string $configName
91
+ *
90
92
* @return \League\Flysystem\AdapterInterface
91
93
*/
92
94
public function getStorageAdapter (string $ configName ): AdapterInterface
@@ -98,6 +100,7 @@ public function getStorageAdapter(string $configName): AdapterInterface
98
100
* Checks if a file upload is present.
99
101
*
100
102
* @param \Cake\Datasource\EntityInterface|\ArrayObject $entity
103
+ *
101
104
* @return bool
102
105
*/
103
106
protected function isFileUploadPresent ($ entity )
@@ -125,6 +128,8 @@ protected function isFileUploadPresent($entity)
125
128
*
126
129
* @param \Cake\Event\EventInterface $event
127
130
* @param \ArrayObject $data
131
+ * @param \ArrayObject $options
132
+ *
128
133
* @return void
129
134
*/
130
135
public function beforeMarshal (EventInterface $ event , ArrayObject $ data , ArrayObject $ options ): void
@@ -140,6 +145,7 @@ public function beforeMarshal(EventInterface $event, ArrayObject $data, ArrayObj
140
145
* @param \Cake\Event\EventInterface $event
141
146
* @param \Cake\Datasource\EntityInterface $entity
142
147
* @param \ArrayObject $options
148
+ *
143
149
* @return void
144
150
*/
145
151
public function beforeSave (EventInterface $ event , EntityInterface $ entity , ArrayObject $ options ): void
@@ -152,7 +158,7 @@ public function beforeSave(EventInterface $event, EntityInterface $entity, Array
152
158
153
159
$ this ->dispatchEvent ('FileStorage.beforeSave ' , [
154
160
'entity ' => $ entity ,
155
- 'storageAdapter ' => $ this ->getStorageAdapter ($ entity ->get ('adapter ' ))
161
+ 'storageAdapter ' => $ this ->getStorageAdapter ($ entity ->get ('adapter ' )),
156
162
], $ this ->getTable ());
157
163
}
158
164
@@ -162,6 +168,9 @@ public function beforeSave(EventInterface $event, EntityInterface $entity, Array
162
168
* @param \Cake\Event\EventInterface $event
163
169
* @param \Cake\Datasource\EntityInterface $entity
164
170
* @param \ArrayObject $options
171
+ *
172
+ * @throws \Exception
173
+ *
165
174
* @return void
166
175
*/
167
176
public function afterSave (EventInterface $ event , EntityInterface $ entity , ArrayObject $ options ): void
@@ -187,20 +196,22 @@ public function afterSave(EventInterface $event, EntityInterface $entity, ArrayO
187
196
);
188
197
} catch (Throwable $ exception ) {
189
198
$ this ->getTable ()->delete ($ entity );
199
+
190
200
throw $ exception ;
191
201
}
192
202
}
193
203
194
204
$ this ->dispatchEvent ('FileStorage.afterSave ' , [
195
205
'entity ' => $ entity ,
196
- 'storageAdapter ' => $ this ->getStorageAdapter ($ entity ->get ('adapter ' ))
206
+ 'storageAdapter ' => $ this ->getStorageAdapter ($ entity ->get ('adapter ' )),
197
207
], $ this ->getTable ());
198
208
}
199
209
200
210
/**
201
211
* checkEntityBeforeSave
202
212
*
203
213
* @param \Cake\Datasource\EntityInterface $entity
214
+ *
204
215
* @return void
205
216
*/
206
217
protected function checkEntityBeforeSave (EntityInterface $ entity )
@@ -222,6 +233,7 @@ protected function checkEntityBeforeSave(EntityInterface $entity)
222
233
* @param \Cake\Event\EventInterface $event
223
234
* @param \Cake\Datasource\EntityInterface $entity
224
235
* @param \ArrayObject $options
236
+ *
225
237
* @return void
226
238
*/
227
239
public function afterDelete (EventInterface $ event , EntityInterface $ entity , ArrayObject $ options ): void
@@ -243,6 +255,7 @@ public function afterDelete(EventInterface $event, EntityInterface $entity, Arra
243
255
*
244
256
* @param array|\ArrayAccess $upload
245
257
* @param string $field
258
+ *
246
259
* @return void
247
260
*/
248
261
protected function getFileInfoFromUpload (&$ upload , $ field = 'file ' )
@@ -268,6 +281,7 @@ protected function getFileInfoFromUpload(&$upload, $field = 'file')
268
281
* callbacks. So the events that will remove the files won't get fired.
269
282
*
270
283
* @param array $conditions Query::where() array structure.
284
+ *
271
285
* @return int Number of deleted records / files
272
286
*/
273
287
public function deleteAllFiles ($ conditions )
@@ -290,6 +304,7 @@ public function deleteAllFiles($conditions)
290
304
291
305
/**
292
306
* @param \Cake\Datasource\EntityInterface $entity Entity
307
+ *
293
308
* @return \Phauthentic\Infrastructure\Storage\FileInterface
294
309
*/
295
310
public function entityToFileObject (EntityInterface $ entity ): FileInterface
@@ -300,6 +315,7 @@ public function entityToFileObject(EntityInterface $entity): FileInterface
300
315
/**
301
316
* @param \Phauthentic\Infrastructure\Storage\FileInterface $file File
302
317
* @param \Cake\Datasource\EntityInterface|null $entity
318
+ *
303
319
* @return \Cake\Datasource\EntityInterface
304
320
*/
305
321
public function fileObjectToEntity (FileInterface $ file , ?EntityInterface $ entity )
@@ -312,6 +328,7 @@ public function fileObjectToEntity(FileInterface $file, ?EntityInterface $entity
312
328
*
313
329
* @param \Phauthentic\Infrastructure\Storage\FileInterface $file File
314
330
* @param \Cake\Datasource\EntityInterface $entity
331
+ *
315
332
* @return \Phauthentic\Infrastructure\Storage\FileInterface
316
333
*/
317
334
public function processImages (FileInterface $ file , EntityInterface $ entity ): FileInterface
@@ -331,6 +348,8 @@ public function processImages(FileInterface $file, EntityInterface $entity): Fil
331
348
}
332
349
333
350
/**
351
+ * @throws \RuntimeException
352
+ *
334
353
* @return \Phauthentic\Infrastructure\Storage\Processor\ProcessorInterface
335
354
*/
336
355
protected function getImageProcessor (): ProcessorInterface
@@ -339,7 +358,7 @@ protected function getImageProcessor(): ProcessorInterface
339
358
return $ this ->imageProcessor ;
340
359
}
341
360
342
- if ($ this ->getConfig ('imageProcessor ' ) instanceOf ProcessorInterface) {
361
+ if ($ this ->getConfig ('imageProcessor ' ) instanceof ProcessorInterface) {
343
362
$ this ->imageProcessor = $ this ->getConfig ('imageProcessor ' );
344
363
}
345
364
0 commit comments