Skip to content

Commit 40611d1

Browse files
committed
Improve Sample
1 parent 3029ead commit 40611d1

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

samples/Basic5/56_OdsToISO8601.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,14 @@ function datesToIso8601(string $infile, Sample $helper): void
4242
. '<number:text>-</number:text>$2',
4343
$newData
4444
) ?? $newData;
45-
$newData = str_replace('number:automatic-order="true"', '', $newData);
45+
$newData = preg_replace(
46+
'~'
47+
. '(<number:date-style [^>]*)'
48+
. ' number:automatic-order="true"'
49+
. '~',
50+
'$1',
51+
$newData
52+
) ?? $newData;
4653
if ($data === $newData) {
4754
$helper->log("no changes needed for $file");
4855
} else {
@@ -60,7 +67,6 @@ function datesToIso8601(string $infile, Sample $helper): void
6067
}
6168
}
6269

63-
$sample = new Sample();
6470
$infileBase = '56_MixedDateFormats.ods';
6571
$infileBase1 = __DIR__ . '/../templates/' . $infileBase;
6672
$infile = realpath($infileBase1);
@@ -70,7 +76,7 @@ function datesToIso8601(string $infile, Sample $helper): void
7076

7177
/** @var Sample $helper */
7278
$helper->log("Infile is $infile");
73-
$outDirectory = $sample->getTemporaryFolder();
79+
$outDirectory = $helper->getTemporaryFolder();
7480
$helper->log("outDirectory is $outDirectory");
7581
$outfile = $outDirectory . '/56_OdsToISO8601.ods';
7682
$helper->log("Outfile is $outfile");
@@ -79,9 +85,7 @@ function datesToIso8601(string $infile, Sample $helper): void
7985
throw new Exception('Copy failed');
8086
}
8187

82-
$helper->log('Copy succeeded');
88+
$helper->log('Update date formatting xml');
8389
datesToIso8601($outfile, $helper);
8490

85-
if ($sample->isCli() === false) {
86-
echo '<a href="/download.php?type=ods' . '&name=' . basename($outfile) . '">Download ' . basename($outfile) . '</a><br />';
87-
}
91+
$helper->addDownloadLink($outfile);

samples/bootstrap/css/phpspreadsheet.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ body {
66
margin-bottom: 20px;
77
}
88
.navbar + h1 {
9-
margin-top: 70px;
9+
margin-top: 100px;
1010
}
1111
.passed {
1212
color: #339900;

src/PhpSpreadsheet/Helper/Sample.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,21 @@ public function write(Spreadsheet $spreadsheet, string $filename, array $writers
131131
$callStartTime = microtime(true);
132132
$writer->save($path);
133133
$this->logWrite($writer, $path, $callStartTime);
134-
if ($this->isCli() === false) {
135-
// @codeCoverageIgnoreStart
136-
echo '<a href="/download.php?type=' . pathinfo($path, PATHINFO_EXTENSION) . '&name=' . basename($path) . '">Download ' . basename($path) . '</a><br />';
137-
// @codeCoverageIgnoreEnd
138-
}
134+
$this->addDownloadLink($path);
139135
}
140136

141137
$this->logEndingNotes();
142138
}
143139

140+
public function addDownloadLink(string $path): void
141+
{
142+
if ($this->isCli() === false) {
143+
// @codeCoverageIgnoreStart
144+
echo '<a href="/download.php?type=' . pathinfo($path, PATHINFO_EXTENSION) . '&name=' . basename($path) . '">Download ' . basename($path) . '</a><br />';
145+
// @codeCoverageIgnoreEnd
146+
}
147+
}
148+
144149
protected function isDirOrMkdir(string $folder): bool
145150
{
146151
return \is_dir($folder) || \mkdir($folder);

0 commit comments

Comments
 (0)