Skip to content

Symfony 7: Services

  • tool (class that does work);

Using external service that do not have specific Symfony implementation

Using autowire attribute

  • TODO study: "Autowire non-autowireable service"

Using autowire configuration

Add in config/services.yaml:

services:

    # FastRicamabi
    ClipParts\:
        resource: '../vendor/fastricambi/common/src/ClipParts/'
        autowire: true

    # WebServCo
    WebServCo\Data\:
        resource: '../vendor/webservco/data/src/WebServCo/Data'
        autowire: true
    WebServCo\Http\:
        resource: '../vendor/webservco/http/src/WebServCo/Http/'
        autowire: true
    WebServCo\Http\Client\:
        resource: '../vendor/webservco/http-client/src/WebServCo/Http/Client'
        autowire: true
    WebServCo\Log\:
        resource: '../vendor/webservco/log/src/WebServCo/Log'
        autowire: true
    WebServCo\Memory\:
        resource: '../vendor/webservco/memory/src/WebServCo/Memory'
        autowire: true
    # Aliases
    Psr\Http\Message\RequestFactoryInterface: '@WebServCo\Http\Factory\Message\Request\RequestFactory'

Check:

symfony console debug:autowiring

symfony console debug:container ClipParts

Using manual approach

  • approach: create a local factory that creates the library object