Declaring services


What is it for?

Based on Symfony services, it is possible to inject objects into your pipeline or workflow. To learn more about services, please visit the official Symfony documentation.

Installation

This plugin is already integrated into the Satellite package, so you can’t require it with the composer.

Usage

If you are using a very simple service, you can define it as follows:

services:
  App\Foo\Bar: ~

Defining your arguments

services:
  App\Foo\Bar:
    arguments:
      - 'my-file.csv' # it's a string argument
      - { host: "localhost", port: '8000' } # it's an array argument
      - 1234 # it's a integer argument

In this example, the App\Foo\Bar service will have 3 parameters that will be passed into the __construct method of your class (in the order of writing).

Making the service public

If you need to make a service public, use the public option which you set to true.

services:
  App\Foo\Bar:
    # ...
    public: true

Using method calls

To understand what calls are, go to the official call documentation.

services:
  App\Foo\Bar:
    # ...
    calls:
      - withUsername: [ 'admin' ]

Using a service as an argument

It’s possible to use a service as an argument when declaring a service by using the service name preceded by @.

services:
  App\Foo\Foo:
    arguments:
      - '@App\Foo\Bar'