Symfony basics

02 Feb 2022 - nicolas

Some Symfony basics


Given this configuration:

        autowire: true
        autoconfigure: true
        public: false

        parent: 'api_platform.doctrine.orm.order_filter'
            id: ~
            name: ~
            updatedAt: ~
            createdAt: ~
        - 'api_platform.filter'
        autowire: false
        autoconfigure: false
        public: false

Our fruit order filter service extends another existing service using tags.

List all services inside the dependency injection container:

php bin/console debug:container

Get details on a service:

php bin/console debug:container serviceNameHere


Given this configuration:

        resource: '../src/*'
        exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php,Client}'

In development, at each HTTP request, Symfony will hash each files under the src/ directory using md5 except those defined in exclude, then compare them with the previously generated cache.

If one hash is different than the previous one, Symfony will create a new cache by generating one php file for each service.

If a service is not used for the request, Symfony will remove the file.

As the project grow, it will take more and more time to do this autodiscovery thing.

To avoid this, explicitly declare each service, like that:

    App\DataFixtures\Faker\Provider\IndexProvider: ~
    App\DataFixtures\Faker\Provider\ValueOrNullProvider: ~