Skip to content

Latest commit

 

History

History
69 lines (51 loc) · 1.64 KB

File metadata and controls

69 lines (51 loc) · 1.64 KB

SprintfTransformer

Return a formatted string, using PHP's vsprintf function.

Transformer reference

  • Service: CleverAge\ProcessBundle\Transformer\String\SprintfTransformer
  • Transformer code: sprintf

Accepted inputs

  • array: each element is used as an argument of the format, in order
  • any other value (scalar, null, \Stringable): used as the single argument of the format

Possible outputs

string

Options

Code Type Required Default Description
format string '%s' The format string; see Notes for %

Examples

  • 'bar' becomes 'foo bar'
# Transformer options level
sprintf:
  format: 'foo %%s'
  • Format one value
# Transformer mapping level
sprintf_one:
  code: '[id]'
  transformers:
    sprintf:
      format: 'one/%%d'
  • Format several values
# Transformer mapping level
sprintf_multiple:
  code:
    - '[firstname]'
    - '[lastname]'
  transformers:
    sprintf:
      format: 'multiple/%%s/%%s'

Notes

In Symfony YAML configuration files, % is used for container parameters: escape it as %% ('%%s' is resolved as '%s'). A format with more placeholders than arguments throws a \ValueError.