Reads a file, whose path is set in the options, and iterates over its lines, outputting each line as a string.
- Service:
CleverAge\ProcessBundle\Task\File\LineReaderTask - Code:
line_reader(task: line_reader) - Iterable task
Input is ignored
string: for each line, its raw content. The line break is not removed.
Underlying class is SplFileObject, with the READ_AHEAD and
SKIP_EMPTY flags. Without DROP_NEW_LINE, the lines keep their line break, so an empty line is output as "\n"
(only the empty string after the last line break is skipped).
| Code | Type | Required | Default | Description |
|---|---|---|---|---|
filename |
string |
X | Path of the file to read. An UnexpectedValueException is thrown if the file does not exist or is not readable |
- Read a file and remove the trailing line break of each line
# Task configuration level
entry:
task: line_reader
options:
filename: '%kernel.project_dir%/var/data/sample.txt'
outputs: [trim]
trim:
task: transformer
options:
transformers:
trim: ~
outputs: [debug]- The file is released once fully read: if the task is executed again (e.g. for a new input), the file is read again from its beginning.
- See also InputLineReaderTask to read a file path given as input.