Skip to content

Commit 344981d

Browse files
Merge pull request #17723 from MauricioFauth/crlf-global
Remove `crlf` global variable
2 parents 5d74cd1 + 873eb09 commit 344981d

38 files changed

Lines changed: 302 additions & 610 deletions

libraries/classes/Controllers/Export/ExportController.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@
3535
use function strlen;
3636
use function time;
3737

38-
use const PHP_EOL;
39-
4038
final class ExportController extends AbstractController
4139
{
4240
/** @var Export */
@@ -56,7 +54,6 @@ public function __invoke(ServerRequest $request): void
5654
$GLOBALS['errorUrl'] = $GLOBALS['errorUrl'] ?? null;
5755
$GLOBALS['message'] = $GLOBALS['message'] ?? null;
5856
$GLOBALS['compression'] = $GLOBALS['compression'] ?? null;
59-
$GLOBALS['crlf'] = $GLOBALS['crlf'] ?? null;
6057
$GLOBALS['asfile'] = $GLOBALS['asfile'] ?? null;
6158
$GLOBALS['buffer_needed'] = $GLOBALS['buffer_needed'] ?? null;
6259
$GLOBALS['save_on_server'] = $GLOBALS['save_on_server'] ?? null;
@@ -261,14 +258,6 @@ public function __invoke(ServerRequest $request): void
261258
// We send fake headers to avoid browser timeout when buffering
262259
$GLOBALS['time_start'] = time();
263260

264-
// Defines the default <CR><LF> format.
265-
// For SQL always use \n as MySQL wants this on all platforms.
266-
if ($GLOBALS['what'] === 'sql') {
267-
$GLOBALS['crlf'] = "\n";
268-
} else {
269-
$GLOBALS['crlf'] = PHP_EOL;
270-
}
271-
272261
$GLOBALS['output_kanji_conversion'] = Encoding::canConvertKanji();
273262

274263
// Do we need to convert charset?
@@ -397,7 +386,6 @@ public function __invoke(ServerRequest $request): void
397386
$GLOBALS['db_select'],
398387
$GLOBALS['whatStrucOrData'],
399388
$GLOBALS['export_plugin'],
400-
$GLOBALS['crlf'],
401389
$GLOBALS['errorUrl'],
402390
$GLOBALS['export_type'],
403391
$GLOBALS['do_relation'],
@@ -431,7 +419,6 @@ public function __invoke(ServerRequest $request): void
431419
$GLOBALS['table_structure'],
432420
$GLOBALS['table_data'],
433421
$GLOBALS['export_plugin'],
434-
$GLOBALS['crlf'],
435422
$GLOBALS['errorUrl'],
436423
$GLOBALS['export_type'],
437424
$GLOBALS['do_relation'],
@@ -452,7 +439,6 @@ public function __invoke(ServerRequest $request): void
452439
$GLOBALS['table_structure'],
453440
$GLOBALS['table_data'],
454441
$GLOBALS['export_plugin'],
455-
$GLOBALS['crlf'],
456442
$GLOBALS['errorUrl'],
457443
$GLOBALS['export_type'],
458444
$GLOBALS['do_relation'],
@@ -467,7 +453,6 @@ public function __invoke(ServerRequest $request): void
467453
Export::exportRaw(
468454
$GLOBALS['whatStrucOrData'],
469455
$GLOBALS['export_plugin'],
470-
$GLOBALS['crlf'],
471456
$GLOBALS['errorUrl'],
472457
$GLOBALS['sql_query'],
473458
$GLOBALS['export_type']
@@ -495,7 +480,6 @@ public function __invoke(ServerRequest $request): void
495480
$GLOBALS['table'],
496481
$GLOBALS['whatStrucOrData'],
497482
$GLOBALS['export_plugin'],
498-
$GLOBALS['crlf'],
499483
$GLOBALS['errorUrl'],
500484
$GLOBALS['export_type'],
501485
$GLOBALS['do_relation'],
@@ -517,7 +501,6 @@ public function __invoke(ServerRequest $request): void
517501
$GLOBALS['table'],
518502
$GLOBALS['whatStrucOrData'],
519503
$GLOBALS['export_plugin'],
520-
$GLOBALS['crlf'],
521504
$GLOBALS['errorUrl'],
522505
$GLOBALS['export_type'],
523506
$GLOBALS['do_relation'],

libraries/classes/Export.php

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ public function getHtmlForDisplayedExportHeader(
562562
* @param string|array $dbSelect the selected databases to export
563563
* @param string $whatStrucOrData structure or data or both
564564
* @param ExportPlugin $exportPlugin the selected export plugin
565-
* @param string $crlf end of line character(s)
566565
* @param string $errorUrl the URL in case of error
567566
* @param string $exportType the export type
568567
* @param bool $doRelation whether to export relation info
@@ -576,7 +575,6 @@ public function exportServer(
576575
$dbSelect,
577576
string $whatStrucOrData,
578577
ExportPlugin $exportPlugin,
579-
string $crlf,
580578
string $errorUrl,
581579
string $exportType,
582580
bool $doRelation,
@@ -605,7 +603,6 @@ public function exportServer(
605603
$tables,
606604
$tables,
607605
$exportPlugin,
608-
$crlf,
609606
$errorUrl,
610607
$exportType,
611608
$doRelation,
@@ -632,7 +629,6 @@ public function exportServer(
632629
* @param array $tableStructure whether to export structure for each table
633630
* @param array $tableData whether to export data for each table
634631
* @param ExportPlugin $exportPlugin the selected export plugin
635-
* @param string $crlf end of line character(s)
636632
* @param string $errorUrl the URL in case of error
637633
* @param string $exportType the export type
638634
* @param bool $doRelation whether to export relation info
@@ -649,7 +645,6 @@ public function exportDatabase(
649645
array $tableStructure,
650646
array $tableData,
651647
ExportPlugin $exportPlugin,
652-
string $crlf,
653648
string $errorUrl,
654649
string $exportType,
655650
bool $doRelation,
@@ -711,7 +706,6 @@ public function exportDatabase(
711706
&& ! $exportPlugin->exportStructure(
712707
$db,
713708
$table,
714-
$crlf,
715709
$errorUrl,
716710
'stand_in',
717711
$exportType,
@@ -747,7 +741,6 @@ public function exportDatabase(
747741
! $exportPlugin->exportStructure(
748742
$db,
749743
$table,
750-
$crlf,
751744
$errorUrl,
752745
'create_table',
753746
$exportType,
@@ -776,7 +769,7 @@ public function exportDatabase(
776769
. ' FROM ' . Util::backquote($db)
777770
. '.' . Util::backquote($table);
778771

779-
if (! $exportPlugin->exportData($db, $table, $crlf, $errorUrl, $localQuery, $aliases)) {
772+
if (! $exportPlugin->exportData($db, $table, $errorUrl, $localQuery, $aliases)) {
780773
break;
781774
}
782775
}
@@ -800,7 +793,6 @@ public function exportDatabase(
800793
! $exportPlugin->exportStructure(
801794
$db,
802795
$table,
803-
$crlf,
804796
$errorUrl,
805797
'triggers',
806798
$exportType,
@@ -832,7 +824,6 @@ public function exportDatabase(
832824
! $exportPlugin->exportStructure(
833825
$db,
834826
$view,
835-
$crlf,
836827
$errorUrl,
837828
'create_view',
838829
$exportType,
@@ -896,15 +887,13 @@ public function exportDatabase(
896887
*
897888
* @param string $whatStrucOrData whether to export structure for each table or raw
898889
* @param ExportPlugin $exportPlugin the selected export plugin
899-
* @param string $crlf end of line character(s)
900890
* @param string $errorUrl the URL in case of error
901891
* @param string $sqlQuery the query to be executed
902892
* @param string $exportType the export type
903893
*/
904894
public static function exportRaw(
905895
string $whatStrucOrData,
906896
ExportPlugin $exportPlugin,
907-
string $crlf,
908897
string $errorUrl,
909898
string $sqlQuery,
910899
string $exportType
@@ -914,7 +903,7 @@ public static function exportRaw(
914903
return;
915904
}
916905

917-
if (! $exportPlugin->exportRawQuery($errorUrl, $sqlQuery, $crlf)) {
906+
if (! $exportPlugin->exportRawQuery($errorUrl, $sqlQuery)) {
918907
$GLOBALS['message'] = Message::error(
919908
// phpcs:disable Generic.Files.LineLength.TooLong
920909
/* l10n: A query written by the user is a "raw query" that could be using no tables or databases in particular */
@@ -932,7 +921,6 @@ public static function exportRaw(
932921
* @param string $table the table to export
933922
* @param string $whatStrucOrData structure or data or both
934923
* @param ExportPlugin $exportPlugin the selected export plugin
935-
* @param string $crlf end of line character(s)
936924
* @param string $errorUrl the URL in case of error
937925
* @param string $exportType the export type
938926
* @param bool $doRelation whether to export relation info
@@ -950,7 +938,6 @@ public function exportTable(
950938
string $table,
951939
string $whatStrucOrData,
952940
ExportPlugin $exportPlugin,
953-
string $crlf,
954941
string $errorUrl,
955942
string $exportType,
956943
bool $doRelation,
@@ -986,7 +973,6 @@ public function exportTable(
986973
! $exportPlugin->exportStructure(
987974
$db,
988975
$table,
989-
$crlf,
990976
$errorUrl,
991977
'create_view',
992978
$exportType,
@@ -1005,7 +991,6 @@ public function exportTable(
1005991
! $exportPlugin->exportStructure(
1006992
$db,
1007993
$table,
1008-
$crlf,
1009994
$errorUrl,
1010995
'create_table',
1011996
$exportType,
@@ -1044,7 +1029,7 @@ public function exportTable(
10441029
. '.' . Util::backquote($table) . $addQuery;
10451030
}
10461031

1047-
if (! $exportPlugin->exportData($db, $table, $crlf, $errorUrl, $localQuery, $aliases)) {
1032+
if (! $exportPlugin->exportData($db, $table, $errorUrl, $localQuery, $aliases)) {
10481033
return;
10491034
}
10501035
}
@@ -1059,7 +1044,6 @@ public function exportTable(
10591044
! $exportPlugin->exportStructure(
10601045
$db,
10611046
$table,
1062-
$crlf,
10631047
$errorUrl,
10641048
'triggers',
10651049
$exportType,

libraries/classes/Operations.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function getViewsAndCreateSqlViewStandIn(
160160

161161
$views[] = $each_table;
162162
// Create stand-in definition to resolve view dependencies
163-
$sql_view_standin = $export_sql_plugin->getTableDefStandIn($db, $each_table, "\n");
163+
$sql_view_standin = $export_sql_plugin->getTableDefStandIn($db, $each_table);
164164
$this->dbi->selectDb($newDatabaseName);
165165
$this->dbi->query($sql_view_standin);
166166
$GLOBALS['sql_query'] .= "\n" . $sql_view_standin;

libraries/classes/Plugins/Export/ExportCodegen.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
use function sprintf;
2424
use function ucfirst;
2525

26+
use const PHP_EOL;
27+
2628
/**
2729
* Handles the export for the CodeGen class
2830
*/
@@ -144,27 +146,25 @@ public function exportDBCreate($db, $exportType, $dbAlias = ''): bool
144146
*
145147
* @param string $db database name
146148
* @param string $table table name
147-
* @param string $crlf the end of line sequence
148149
* @param string $errorUrl the url to go back in case of error
149150
* @param string $sqlQuery SQL query for obtaining data
150151
* @param array $aliases Aliases of db/table/columns
151152
*/
152153
public function exportData(
153154
$db,
154155
$table,
155-
$crlf,
156156
$errorUrl,
157157
$sqlQuery,
158158
array $aliases = []
159159
): bool {
160160
$format = (int) $GLOBALS['codegen_format'];
161161

162162
if ($format === self::HANDLER_NHIBERNATE_CS) {
163-
return $this->export->outputHandler($this->handleNHibernateCSBody($db, $table, $crlf, $aliases));
163+
return $this->export->outputHandler($this->handleNHibernateCSBody($db, $table, $aliases));
164164
}
165165

166166
if ($format === self::HANDLER_NHIBERNATE_XML) {
167-
return $this->export->outputHandler($this->handleNHibernateXMLBody($db, $table, $crlf, $aliases));
167+
return $this->export->outputHandler($this->handleNHibernateXMLBody($db, $table, $aliases));
168168
}
169169

170170
return $this->export->outputHandler(sprintf('%s is not supported.', $format));
@@ -199,12 +199,11 @@ public static function cgMakeIdentifier($str, $ucfirst = true)
199199
*
200200
* @param string $db database name
201201
* @param string $table table name
202-
* @param string $crlf line separator
203202
* @param array $aliases Aliases of db/table/columns
204203
*
205204
* @return string containing C# code lines, separated by "\n"
206205
*/
207-
private function handleNHibernateCSBody($db, $table, $crlf, array $aliases = [])
206+
private function handleNHibernateCSBody($db, $table, array $aliases = [])
208207
{
209208
$db_alias = $db;
210209
$table_alias = $table;
@@ -294,23 +293,21 @@ private function handleNHibernateCSBody($db, $table, $crlf, array $aliases = [])
294293
$lines[] = ' #endregion';
295294
$lines[] = '}';
296295

297-
return implode($crlf, $lines);
296+
return implode(PHP_EOL, $lines);
298297
}
299298

300299
/**
301300
* XML Handler
302301
*
303302
* @param string $db database name
304303
* @param string $table table name
305-
* @param string $crlf line separator
306304
* @param array $aliases Aliases of db/table/columns
307305
*
308306
* @return string containing XML code lines, separated by "\n"
309307
*/
310308
private function handleNHibernateXMLBody(
311309
$db,
312310
$table,
313-
$crlf,
314311
array $aliases = []
315312
) {
316313
$db_alias = $db;
@@ -363,7 +360,7 @@ private function handleNHibernateXMLBody(
363360
$lines[] = ' </class>';
364361
$lines[] = '</hibernate-mapping>';
365362

366-
return implode($crlf, $lines);
363+
return implode(PHP_EOL, $lines);
367364
}
368365

369366
/**

libraries/classes/Plugins/Export/ExportCsv.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
use function str_replace;
2424
use function trim;
2525

26+
use const PHP_EOL;
27+
2628
/**
2729
* Handles the export for the CSV format
2830
*/
@@ -137,7 +139,7 @@ public function exportHeader(): bool
137139
}
138140
} else {
139141
if (empty($GLOBALS['csv_terminated']) || mb_strtolower($GLOBALS['csv_terminated']) === 'auto') {
140-
$GLOBALS['csv_terminated'] = $GLOBALS['crlf'];
142+
$GLOBALS['csv_terminated'] = PHP_EOL;
141143
} else {
142144
$GLOBALS['csv_terminated'] = str_replace(
143145
[
@@ -206,15 +208,13 @@ public function exportDBCreate($db, $exportType, $dbAlias = ''): bool
206208
*
207209
* @param string $db database name
208210
* @param string $table table name
209-
* @param string $crlf the end of line sequence
210211
* @param string $errorUrl the url to go back in case of error
211212
* @param string $sqlQuery SQL query for obtaining data
212213
* @param array $aliases Aliases of db/table/columns
213214
*/
214215
public function exportData(
215216
$db,
216217
$table,
217-
$crlf,
218218
$errorUrl,
219219
$sqlQuery,
220220
array $aliases = []
@@ -343,10 +343,9 @@ public function exportData(
343343
*
344344
* @param string $errorUrl the url to go back in case of error
345345
* @param string $sqlQuery the rawquery to output
346-
* @param string $crlf the end of line sequence
347346
*/
348-
public function exportRawQuery(string $errorUrl, string $sqlQuery, string $crlf): bool
347+
public function exportRawQuery(string $errorUrl, string $sqlQuery): bool
349348
{
350-
return $this->exportData('', '', $crlf, $errorUrl, $sqlQuery);
349+
return $this->exportData('', '', $errorUrl, $sqlQuery);
351350
}
352351
}

0 commit comments

Comments
 (0)