Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions docs/reference/tasks/csv_writer_task.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,38 @@ Possible outputs
Options
-------

| Code | Type | Required | Default | Description |
| ---- | ---- | :------: | ------- | ----------- |
| `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 |
| `delimiter` | `string` | | `;` | CSV delimiter |
| `enclosure` | `string` | | `"` | CSV enclosure character |
| `escape` | `string` | | `\\` | CSV escape character |
| `headers` | `array` or `null` | | `null` | Static list of CSV headers, without the option, it will be dynamically read from first line |
| `mode` | `string` | | `wb` | File open mode (see [fopen mode parameter](https://secure.php.net/manual/en/function.fopen.php)) |
| `split_character` | `string` | | `\|` | Used to implode array values |
| `write_headers` | `bool` | | `true` | Write the headers as a first line |
| Code | Type | Required | Default | Description |
|-------------------|-------------------|:--------:|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `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 |
| `delimiter` | `string` | | `;` | CSV delimiter |
| `enclosure` | `string` | | `"` | CSV enclosure character |
| `escape` | `string` | | `\\` | CSV escape character |
| `headers` | `array` or `null` | | `null` | Static list of CSV headers, without the option, it will be dynamically read from first line |
| `mode` | `string` | | `wb` | File open mode (see [fopen mode parameter](https://secure.php.net/manual/en/function.fopen.php)) |
| `split_character` | `string` | | `\|` | Used to implode array values |
| `write_headers` | `bool` | | `true` | Write the headers as a first line |

Example
----------------

```yaml
# Task configuration level
entry:
service: '@CleverAge\ProcessBundle\Task\ConstantIterableOutputTask'
outputs: [ write ]
options:
output:
- column1: value1-1
column2: value2-1
column3: value3-1
- column1: value1-2
column2: value2-2
column3: value3-2
- column1: ''
column2: null
column3: value3-3
write:
service: '@CleverAge\ProcessBundle\Task\File\Csv\CsvWriterTask'
options:
file_path: '%kernel.project_dir%/var/data/csv_writer_{date_time}.csv'
```
1 change: 1 addition & 0 deletions src/Task/File/Csv/CsvWriterTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected function configureOptions(OptionsResolver $resolver): void
[
'{date}' => date('Ymd'),
'{date_time}' => date('Ymd_His'),
'{timestamp}' => time(),
'{unique_token}' => uniqid('', true),
]
)
Expand Down