@@ -30,7 +30,7 @@ class UploadCollectionSubscriber implements EventSubscriberInterface
30
30
/**
31
31
* @var boolean Primary Key field
32
32
*/
33
- protected $ primary_key ;
33
+ protected $ primaryKey ;
34
34
35
35
/**
36
36
* @var boolean Is file nameable
@@ -40,7 +40,7 @@ class UploadCollectionSubscriber implements EventSubscriberInterface
40
40
/**
41
41
* @var string Nameable field name
42
42
*/
43
- protected $ nameable_field ;
43
+ protected $ nameableField ;
44
44
45
45
/**
46
46
* Used to revert changes if form is not valid.
@@ -61,17 +61,17 @@ class UploadCollectionSubscriber implements EventSubscriberInterface
61
61
/**
62
62
* @var array Submitted primary keys
63
63
*/
64
- protected $ submitted_pk ;
64
+ protected $ submittedPk ;
65
65
66
66
/**
67
67
* @var boolean
68
68
*/
69
- protected $ allow_add ;
69
+ protected $ allowAdd ;
70
70
71
71
/**
72
72
* @var boolean
73
73
*/
74
- protected $ allow_delete ;
74
+ protected $ allowDelete ;
75
75
76
76
/**
77
77
* @var FileStorageInterface
@@ -88,14 +88,14 @@ public function __construct($propertyName, array $options, FileStorageInterface
88
88
{
89
89
$ this ->propertyName = $ propertyName ;
90
90
$ this ->dataClass = $ options ['options ' ]['data_class ' ];
91
- $ this ->primary_key = $ options ['primary_key ' ];
91
+ $ this ->primaryKey = $ options ['primary_key ' ];
92
92
$ this ->nameable = $ options ['nameable ' ];
93
- $ this ->nameable_field = $ options ['nameable_field ' ];
93
+ $ this ->nameableField = $ options ['nameable_field ' ];
94
94
$ this ->uploads = array ();
95
95
$ this ->editable = array ();
96
- $ this ->submitted_pk = array ();
97
- $ this ->allow_add = $ options ['allow_add ' ];
98
- $ this ->allow_delete = $ options ['allow_delete ' ];
96
+ $ this ->submittedPk = array ();
97
+ $ this ->allowAdd = $ options ['allow_add ' ];
98
+ $ this ->allowDelete = $ options ['allow_delete ' ];
99
99
$ this ->storage = $ storage ;
100
100
}
101
101
@@ -110,7 +110,6 @@ public static function getSubscribedEvents()
110
110
111
111
public function preSubmit (FormEvent $ event )
112
112
{
113
- $ form = $ event ->getForm ();
114
113
$ data = $ event ->getData ();
115
114
116
115
$ data = $ data ?: array ();
@@ -142,8 +141,8 @@ public function preSubmit(FormEvent $event)
142
141
143
142
// save submitted primary keys for onSubmit event
144
143
foreach ($ data as $ file ) {
145
- if (is_array ($ file ) && array_key_exists ($ this ->primary_key , $ file )) {
146
- $ this ->submitted_pk [] = $ file [$ this ->primary_key ];
144
+ if (is_array ($ file ) && array_key_exists ($ this ->primaryKey , $ file )) {
145
+ $ this ->submittedPk [] = $ file [$ this ->primaryKey ];
147
146
}
148
147
}
149
148
@@ -159,17 +158,17 @@ public function onSubmit(FormEvent $event)
159
158
$ getter = 'get ' .ucfirst ($ this ->propertyName );
160
159
$ this ->originalFiles = $ data ->$ getter ();
161
160
162
- if ($ this ->allow_delete ) {
161
+ if ($ this ->allowDelete ) {
163
162
// remove files not present in submitted pk
164
- $ pkGetter = 'get ' .ucfirst ($ this ->primary_key );
163
+ $ pkGetter = 'get ' .ucfirst ($ this ->primaryKey );
165
164
foreach ($ data ->$ getter () as $ file ) {
166
- if (!in_array ($ file ->$ pkGetter (), $ this ->submitted_pk )) {
165
+ if (!in_array ($ file ->$ pkGetter (), $ this ->submittedPk )) {
167
166
$ data ->$ getter ()->removeElement ($ file );
168
167
}
169
168
}
170
169
}
171
170
172
- if ($ this ->allow_add ) {
171
+ if ($ this ->allowAdd ) {
173
172
// create file entites for each file
174
173
foreach ($ this ->uploads as $ upload ) {
175
174
if (!is_object ($ upload ) && !is_null ($ this ->storage )) {
@@ -196,8 +195,8 @@ public function onSubmit(FormEvent $event)
196
195
}
197
196
198
197
// if nameable field specified - set normalized name
199
- if ($ this ->nameable && $ this ->nameable_field ) {
200
- $ setNameable = 'set ' .ucfirst ($ this ->nameable_field );
198
+ if ($ this ->nameable && $ this ->nameableField ) {
199
+ $ setNameable = 'set ' .ucfirst ($ this ->nameableField );
201
200
202
201
// this value is unsafe
203
202
$ name = $ upload ->getClientOriginalName ();
@@ -235,70 +234,70 @@ public function postSubmit(FormEvent $event)
235
234
private function normalizeUtf8String ($ s )
236
235
{
237
236
// save original string
238
- $ original_string = $ s ;
237
+ $ originalString = $ s ;
239
238
240
239
// Normalizer-class missing!
241
240
if (!class_exists ('\Normalizer ' )) {
242
241
// remove all non-whitelisted characters
243
- return preg_replace ( '@[^a-zA-Z0-9._\-\s ]@u ' , "" , $ original_string );
242
+ return preg_replace ( '@[^a-zA-Z0-9._\-\s ]@u ' , '' , $ originalString );
244
243
}
245
244
246
245
$ normalizer = new \Normalizer ();
247
246
248
247
// maps German (umlauts) and other European characters onto two characters before just removing diacritics
249
- $ s = preg_replace ('@\x{00c4}@u ' , " AE " , $ s ); // umlaut Ä => AE
250
- $ s = preg_replace ('@\x{00d6}@u ' , " OE " , $ s ); // umlaut Ö => OE
251
- $ s = preg_replace ('@\x{00dc}@u ' , " UE " , $ s ); // umlaut Ü => UE
252
- $ s = preg_replace ('@\x{00e4}@u ' , " ae " , $ s ); // umlaut ä => ae
253
- $ s = preg_replace ('@\x{00f6}@u ' , " oe " , $ s ); // umlaut ö => oe
254
- $ s = preg_replace ('@\x{00fc}@u ' , " ue " , $ s ); // umlaut ü => ue
255
- $ s = preg_replace ('@\x{00f1}@u ' , " ny " , $ s ); // ñ => ny
256
- $ s = preg_replace ('@\x{00ff}@u ' , " yu " , $ s ); // ÿ => yu
248
+ $ s = preg_replace ('@\x{00c4}@u ' , ' AE ' , $ s ); // umlaut Ä => AE
249
+ $ s = preg_replace ('@\x{00d6}@u ' , ' OE ' , $ s ); // umlaut Ö => OE
250
+ $ s = preg_replace ('@\x{00dc}@u ' , ' UE ' , $ s ); // umlaut Ü => UE
251
+ $ s = preg_replace ('@\x{00e4}@u ' , ' ae ' , $ s ); // umlaut ä => ae
252
+ $ s = preg_replace ('@\x{00f6}@u ' , ' oe ' , $ s ); // umlaut ö => oe
253
+ $ s = preg_replace ('@\x{00fc}@u ' , ' ue ' , $ s ); // umlaut ü => ue
254
+ $ s = preg_replace ('@\x{00f1}@u ' , ' ny ' , $ s ); // ñ => ny
255
+ $ s = preg_replace ('@\x{00ff}@u ' , ' yu ' , $ s ); // ÿ => yu
257
256
258
257
// maps special characters (characters with diacritics) on their base-character followed by the diacritical mark
259
258
// exmaple: Ú => U´, á => a`
260
259
$ s = $ normalizer ->normalize ($ s , $ normalizer ::FORM_D );
261
260
262
261
$ s = preg_replace ('@\pM@u ' , "" , $ s ); // removes diacritics
263
262
264
- $ s = preg_replace ('@\x{00df}@u ' , " ss " , $ s ); // maps German ß onto ss
265
- $ s = preg_replace ('@\x{00c6}@u ' , " AE " , $ s ); // Æ => AE
266
- $ s = preg_replace ('@\x{00e6}@u ' , " ae " , $ s ); // æ => ae
267
- $ s = preg_replace ('@\x{0132}@u ' , " IJ " , $ s ); // ? => IJ
268
- $ s = preg_replace ('@\x{0133}@u ' , " ij " , $ s ); // ? => ij
269
- $ s = preg_replace ('@\x{0152}@u ' , " OE " , $ s ); // Œ => OE
270
- $ s = preg_replace ('@\x{0153}@u ' , " oe " , $ s ); // œ => oe
271
-
272
- $ s = preg_replace ('@\x{00d0}@u ' , " D " , $ s ); // Ð => D
273
- $ s = preg_replace ('@\x{0110}@u ' , " D " , $ s ); // Ð => D
274
- $ s = preg_replace ('@\x{00f0}@u ' , " d " , $ s ); // ð => d
275
- $ s = preg_replace ('@\x{0111}@u ' , " d " , $ s ); // d => d
276
- $ s = preg_replace ('@\x{0126}@u ' , " H " , $ s ); // H => H
277
- $ s = preg_replace ('@\x{0127}@u ' , " h " , $ s ); // h => h
278
- $ s = preg_replace ('@\x{0131}@u ' , " i " , $ s ); // i => i
279
- $ s = preg_replace ('@\x{0138}@u ' , " k " , $ s ); // ? => k
280
- $ s = preg_replace ('@\x{013f}@u ' , " L " , $ s ); // ? => L
281
- $ s = preg_replace ('@\x{0141}@u ' , " L " , $ s ); // L => L
282
- $ s = preg_replace ('@\x{0140}@u ' , " l " , $ s ); // ? => l
283
- $ s = preg_replace ('@\x{0142}@u ' , " l " , $ s ); // l => l
284
- $ s = preg_replace ('@\x{014a}@u ' , " N " , $ s ); // ? => N
285
- $ s = preg_replace ('@\x{0149}@u ' , " n " , $ s ); // ? => n
286
- $ s = preg_replace ('@\x{014b}@u ' , " n " , $ s ); // ? => n
287
- $ s = preg_replace ('@\x{00d8}@u ' , " O " , $ s ); // Ø => O
288
- $ s = preg_replace ('@\x{00f8}@u ' , " o " , $ s ); // ø => o
289
- $ s = preg_replace ('@\x{017f}@u ' , " s " , $ s ); // ? => s
290
- $ s = preg_replace ('@\x{00de}@u ' , " T " , $ s ); // Þ => T
291
- $ s = preg_replace ('@\x{0166}@u ' , " T " , $ s ); // T => T
292
- $ s = preg_replace ('@\x{00fe}@u ' , " t " , $ s ); // þ => t
293
- $ s = preg_replace ('@\x{0167}@u ' , " t " , $ s ); // t => t
263
+ $ s = preg_replace ('@\x{00df}@u ' , ' ss ' , $ s ); // maps German ß onto ss
264
+ $ s = preg_replace ('@\x{00c6}@u ' , ' AE ' , $ s ); // Æ => AE
265
+ $ s = preg_replace ('@\x{00e6}@u ' , ' ae ' , $ s ); // æ => ae
266
+ $ s = preg_replace ('@\x{0132}@u ' , ' IJ ' , $ s ); // ? => IJ
267
+ $ s = preg_replace ('@\x{0133}@u ' , ' ij ' , $ s ); // ? => ij
268
+ $ s = preg_replace ('@\x{0152}@u ' , ' OE ' , $ s ); // Œ => OE
269
+ $ s = preg_replace ('@\x{0153}@u ' , ' oe ' , $ s ); // œ => oe
270
+
271
+ $ s = preg_replace ('@\x{00d0}@u ' , ' D ' , $ s ); // Ð => D
272
+ $ s = preg_replace ('@\x{0110}@u ' , ' D ' , $ s ); // Ð => D
273
+ $ s = preg_replace ('@\x{00f0}@u ' , ' d ' , $ s ); // ð => d
274
+ $ s = preg_replace ('@\x{0111}@u ' , ' d ' , $ s ); // d => d
275
+ $ s = preg_replace ('@\x{0126}@u ' , ' H ' , $ s ); // H => H
276
+ $ s = preg_replace ('@\x{0127}@u ' , ' h ' , $ s ); // h => h
277
+ $ s = preg_replace ('@\x{0131}@u ' , ' i ' , $ s ); // i => i
278
+ $ s = preg_replace ('@\x{0138}@u ' , ' k ' , $ s ); // ? => k
279
+ $ s = preg_replace ('@\x{013f}@u ' , ' L ' , $ s ); // ? => L
280
+ $ s = preg_replace ('@\x{0141}@u ' , ' L ' , $ s ); // L => L
281
+ $ s = preg_replace ('@\x{0140}@u ' , ' l ' , $ s ); // ? => l
282
+ $ s = preg_replace ('@\x{0142}@u ' , ' l ' , $ s ); // l => l
283
+ $ s = preg_replace ('@\x{014a}@u ' , ' N ' , $ s ); // ? => N
284
+ $ s = preg_replace ('@\x{0149}@u ' , ' n ' , $ s ); // ? => n
285
+ $ s = preg_replace ('@\x{014b}@u ' , ' n ' , $ s ); // ? => n
286
+ $ s = preg_replace ('@\x{00d8}@u ' , ' O ' , $ s ); // Ø => O
287
+ $ s = preg_replace ('@\x{00f8}@u ' , ' o ' , $ s ); // ø => o
288
+ $ s = preg_replace ('@\x{017f}@u ' , ' s ' , $ s ); // ? => s
289
+ $ s = preg_replace ('@\x{00de}@u ' , ' T ' , $ s ); // Þ => T
290
+ $ s = preg_replace ('@\x{0166}@u ' , ' T ' , $ s ); // T => T
291
+ $ s = preg_replace ('@\x{00fe}@u ' , ' t ' , $ s ); // þ => t
292
+ $ s = preg_replace ('@\x{0167}@u ' , ' t ' , $ s ); // t => t
294
293
295
294
// remove all non-ASCii characters
296
- $ s = preg_replace ('@[^\0-\x80]@u ' , "" , $ s );
295
+ $ s = preg_replace ('@[^\0-\x80]@u ' , '' , $ s );
297
296
298
297
// possible errors in UTF8-regular-expressions
299
298
if (empty ($ s )) {
300
299
// remove all non-whitelisted characters
301
- return preg_replace ('@[^a-zA-Z0-9._\-\s ]@u ' , "" , $ original_string );
300
+ return preg_replace ('@[^a-zA-Z0-9._\-\s ]@u ' , '' , $ originalString );
302
301
}
303
302
304
303
// return normalized string
0 commit comments