Skip to content

Latest commit

 

History

History
56 lines (42 loc) · 1.68 KB

File metadata and controls

56 lines (42 loc) · 1.68 KB

LineReaderTask

Reads a file, whose path is set in the options, and iterates over its lines, outputting each line as a string.

Task reference

  • Service: CleverAge\ProcessBundle\Task\File\LineReaderTask
  • Iterable task

Accepted inputs

Input is ignored

Possible outputs

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.

Options

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

Examples

  • Read a file and remove the trailing line break of each line
# Task configuration level
entry:
  service: '@CleverAge\ProcessBundle\Task\File\LineReaderTask'
  options:
    filename: '%kernel.project_dir%/var/data/sample.txt'
  outputs: [trim]
trim:
  service: '@CleverAge\ProcessBundle\Task\TransformerTask'
  options:
    transformers:
      trim: ~
  outputs: [debug]

Notes

  • 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.