@@ -102,22 +102,24 @@ public function exportEntities(AbstractNamedDBElement|array $entities, array $op
102102 $ groups [] = 'include_children ' ;
103103 }
104104
105- return $ this ->serializer ->serialize ($ entities , $ options ['format ' ],
105+ return $ this ->serializer ->serialize (
106+ $ entities ,
107+ $ options ['format ' ],
106108 [
107109 'groups ' => $ groups ,
108110 'as_collection ' => true ,
109111 'csv_delimiter ' => $ options ['csv_delimiter ' ],
110112 'xml_root_node_name ' => 'PartDBExport ' ,
111113 'partdb_export ' => true ,
112- //Skip the item normalizer, so that we dont get IRIs in the output
114+ //Skip the item normalizer, so that we dont get IRIs in the output
113115 SkippableItemNormalizer::DISABLE_ITEM_NORMALIZER => true ,
114- //Handle circular references
116+ //Handle circular references
115117 AbstractNormalizer::CIRCULAR_REFERENCE_HANDLER => $ this ->handleCircularReference (...),
116118 ]
117119 );
118120 }
119121
120- private function handleCircularReference (object $ object, string $ format , array $ context ): string
122+ private function handleCircularReference (object $ object ): string
121123 {
122124 if ($ object instanceof AbstractStructuralDBElement) {
123125 return $ object ->getFullPath ("-> " );
@@ -127,7 +129,7 @@ private function handleCircularReference(object $object, string $format, array $
127129 return $ object ->__toString ();
128130 }
129131
130- throw new CircularReferenceException ('Circular reference detected for object of type ' . get_class ($ object ));
132+ throw new CircularReferenceException ('Circular reference detected for object of type ' . get_class ($ object ));
131133 }
132134
133135 /**
@@ -148,7 +150,9 @@ protected function exportToExcel(array $entities, array $options): string
148150 $ groups [] = 'include_children ' ;
149151 }
150152
151- $ csvData = $ this ->serializer ->serialize ($ entities , 'csv ' ,
153+ $ csvData = $ this ->serializer ->serialize (
154+ $ entities ,
155+ 'csv ' ,
152156 [
153157 'groups ' => $ groups ,
154158 'as_collection ' => true ,
@@ -162,18 +166,18 @@ protected function exportToExcel(array $entities, array $options): string
162166 //Convert CSV to Excel
163167 $ spreadsheet = new Spreadsheet ();
164168 $ worksheet = $ spreadsheet ->getActiveSheet ();
165-
169+
166170 $ rows = explode ("\n" , $ csvData );
167171 $ rowIndex = 1 ;
168-
172+
169173 foreach ($ rows as $ row ) {
170174 if (trim ($ row ) === '' ) {
171175 continue ;
172176 }
173-
174- $ columns = str_getcsv ($ row , $ options ['csv_delimiter ' ]);
177+
178+ $ columns = str_getcsv ($ row , $ options ['csv_delimiter ' ], ' " ' , '\\' );
175179 $ colIndex = 1 ;
176-
180+
177181 foreach ($ columns as $ column ) {
178182 $ cellCoordinate = \PhpOffice \PhpSpreadsheet \Cell \Coordinate::stringFromColumnIndex ($ colIndex ) . $ rowIndex ;
179183 $ worksheet ->setCellValue ($ cellCoordinate , $ column );
@@ -183,17 +187,13 @@ protected function exportToExcel(array $entities, array $options): string
183187 }
184188
185189 //Save to memory stream
186- if ($ options ['format ' ] === 'xlsx ' ) {
187- $ writer = new Xlsx ($ spreadsheet );
188- } else {
189- $ writer = new Xls ($ spreadsheet );
190- }
191-
190+ $ writer = $ options ['format ' ] === 'xlsx ' ? new Xlsx ($ spreadsheet ) : new Xls ($ spreadsheet );
191+
192192 ob_start ();
193193 $ writer ->save ('php://output ' );
194194 $ content = ob_get_contents ();
195195 ob_end_clean ();
196-
196+
197197 return $ content ;
198198 }
199199
@@ -231,25 +231,15 @@ public function exportEntityFromRequest(AbstractNamedDBElement|array $entities,
231231
232232 //Determine the content type for the response
233233
234- //Plain text should work for all types
235- $ content_type = 'text/plain ' ;
236-
237234 //Try to use better content types based on the format
238235 $ format = $ options ['format ' ];
239- switch ($ format ) {
240- case 'xml ' :
241- $ content_type = 'application/xml ' ;
242- break ;
243- case 'json ' :
244- $ content_type = 'application/json ' ;
245- break ;
246- case 'xlsx ' :
247- $ content_type = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ' ;
248- break ;
249- case 'xls ' :
250- $ content_type = 'application/vnd.ms-excel ' ;
251- break ;
252- }
236+ $ content_type = match ($ format ) {
237+ 'xml ' => 'application/xml ' ,
238+ 'json ' => 'application/json ' ,
239+ 'xlsx ' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet ' ,
240+ 'xls ' => 'application/vnd.ms-excel ' ,
241+ default => 'text/plain ' ,
242+ };
253243 $ response ->headers ->set ('Content-Type ' , $ content_type );
254244
255245 //If view option is not specified, then download the file.
@@ -267,7 +257,7 @@ public function exportEntityFromRequest(AbstractNamedDBElement|array $entities,
267257
268258 $ level = $ options ['level ' ];
269259
270- $ filename = ' export_ ' . $ entity_name. ' _ ' . $ level. ' . ' . $ format ;
260+ $ filename = " export_ { $ entity_name} _ { $ level} . { $ format}" ;
271261
272262 //Sanitize the filename
273263 $ filename = FilenameSanatizer::sanitizeFilename ($ filename );
0 commit comments