Skip to content

Commit 6dea11d

Browse files
Merge pull request #163 from cleverage/162
#162 Add timestamp placeholder on file_path parameter of CsvWriterTas…
2 parents 24b1202 + b4a8033 commit 6dea11d

File tree

2 files changed

+36
-10
lines changed

2 files changed

+36
-10
lines changed

docs/reference/tasks/csv_writer_task.md

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,38 @@ Possible outputs
2424
Options
2525
-------
2626

27-
| Code | Type | Required | Default | Description |
28-
| ---- | ---- | :------: | ------- | ----------- |
29-
| `file_path` | `string` | **X** | | Path of the file to write to (relative to symfony root or absolute). It can also take two placeholders (`{date}` and `{date_time}`) to insert timestamps into the filename |
30-
| `delimiter` | `string` | | `;` | CSV delimiter |
31-
| `enclosure` | `string` | | `"` | CSV enclosure character |
32-
| `escape` | `string` | | `\\` | CSV escape character |
33-
| `headers` | `array` or `null` | | `null` | Static list of CSV headers, without the option, it will be dynamically read from first line |
34-
| `mode` | `string` | | `wb` | File open mode (see [fopen mode parameter](https://secure.php.net/manual/en/function.fopen.php)) |
35-
| `split_character` | `string` | | `\|` | Used to implode array values |
36-
| `write_headers` | `bool` | | `true` | Write the headers as a first line |
27+
| Code | Type | Required | Default | Description |
28+
|-------------------|-------------------|:--------:|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
29+
| `file_path` | `string` | **X** | | Path of the file to write to (relative to symfony root or absolute).<br/>It can also take placeholders (`{date}`, `{date_time}`, `{timestamp}` `{unique_token}`) to insert data into the filename |
30+
| `delimiter` | `string` | | `;` | CSV delimiter |
31+
| `enclosure` | `string` | | `"` | CSV enclosure character |
32+
| `escape` | `string` | | `\\` | CSV escape character |
33+
| `headers` | `array` or `null` | | `null` | Static list of CSV headers, without the option, it will be dynamically read from first line |
34+
| `mode` | `string` | | `wb` | File open mode (see [fopen mode parameter](https://secure.php.net/manual/en/function.fopen.php)) |
35+
| `split_character` | `string` | | `\|` | Used to implode array values |
36+
| `write_headers` | `bool` | | `true` | Write the headers as a first line |
37+
38+
Example
39+
----------------
40+
41+
```yaml
42+
# Task configuration level
43+
entry:
44+
service: '@CleverAge\ProcessBundle\Task\ConstantIterableOutputTask'
45+
outputs: [ write ]
46+
options:
47+
output:
48+
- column1: value1-1
49+
column2: value2-1
50+
column3: value3-1
51+
- column1: value1-2
52+
column2: value2-2
53+
column3: value3-2
54+
- column1: ''
55+
column2: null
56+
column3: value3-3
57+
write:
58+
service: '@CleverAge\ProcessBundle\Task\File\Csv\CsvWriterTask'
59+
options:
60+
file_path: '%kernel.project_dir%/var/data/csv_writer_{date_time}.csv'
61+
```

src/Task/File/Csv/CsvWriterTask.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ protected function configureOptions(OptionsResolver $resolver): void
5959
[
6060
'{date}' => date('Ymd'),
6161
'{date_time}' => date('Ymd_His'),
62+
'{timestamp}' => time(),
6263
'{unique_token}' => uniqid('', true),
6364
]
6465
)

0 commit comments

Comments
 (0)