Skip to content

Commit 9ffb0db

Browse files
committed
More proper filenames in CsvWriter.
1 parent 1cf54ea commit 9ffb0db

File tree

2 files changed

+15
-33
lines changed

2 files changed

+15
-33
lines changed

examples/example-downloaded.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
$client->addProcessor(
2323
Gwt_Processor_CsvWriter::factory(array(
2424
'savePath' => '.',
25-
'dateFormat' => 'Ymd-His',
26-
'filenameTemplate' => '{website}' . DIRECTORY_SEPARATOR . '{tableName}-{date}.csv',
25+
'dateFormat' => 'Ymd',
26+
'filenameTemplate' => '{website}' . DIRECTORY_SEPARATOR . '{tableName}-{dateStart}-{dateEnd}.csv',
2727
))
2828
);
2929
foreach ($sites as $site => $siteOptions) {

src/Gwt/Processor/CsvWriter.php

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ class Gwt_Processor_CsvWriter
4040
*
4141
* @var string
4242
*/
43-
private $_dateFormat = 'Ymd-His';
43+
private $_dateFormat = 'Ymd';
4444

4545
/**
4646
* Template used to build filename
4747
*
4848
* @var string
4949
*/
50-
private $_filenameTemplate = '{website}-{tableName}-{date}.csv';
50+
private $_filenameTemplate = '{website}-{tableName}-{dateStart}-{dateEnd}.csv';
5151

5252
/**
5353
* Process data
@@ -136,33 +136,6 @@ public function setDateFormat($dateFormat)
136136
return $this;
137137
}
138138

139-
/**
140-
* Set datetime to be used in filename
141-
*
142-
* @todo use clients dateStart-dateEnd
143-
* @param DateTime $dt
144-
* @return void
145-
*/
146-
public function setDateTime(DateTime $dt)
147-
{
148-
$this->_dt = $dt;
149-
}
150-
151-
/**
152-
* Get datetime to be used in filename
153-
*
154-
* @todo use clients dateStart-dateEnd
155-
* @return DateTime
156-
*/
157-
public function getDateTime()
158-
{
159-
if (null !== $this->_dt) {
160-
return $this->_dt;
161-
}
162-
163-
return new DateTime('now', new DateTimeZone('UTC'));
164-
}
165-
166139
/**
167140
* Build filename using template
168141
*
@@ -179,10 +152,19 @@ protected function buildFilename($tableName)
179152
);
180153
$filename = str_replace('{tableName}', $tableName, $filename);
181154
$filename = str_replace(
182-
'{date}',
183-
$this->getDateTime()->format($this->getDateFormat()),
155+
'{dateStart}',
156+
$this->getClient()->getDateStart()->format($this->getDateFormat()),
184157
$filename
185158
);
159+
$filename = str_replace(
160+
'{dateEnd}',
161+
$this->getClient()->getDateEnd()->format($this->getDateFormat()),
162+
$filename
163+
);
164+
165+
if (preg_match('#{[^}]*}#', $filename, $matches)) {
166+
throw new Exception('Unknown placeholder is found: ' . var_export($matches[0], true));
167+
}
186168

187169
return $filename;
188170
}

0 commit comments

Comments
 (0)