Skip to content

Document the exclusion of src/DataFixtures/ for prod (dev dependency) #537

@GromNaN

Description

@GromNaN

Fixture classes must implement the Doctrine\Common\DataFixtures\FixtureInterface. But this package is a "dev-dependency" that can be skipped for "prod" deployments.

When Symfony is configured to discover the src/ directory, the fixture classes are automatically registered as service in the DIC. But when the doctrine/data-fixtures package is not installed, the files in src/DataFixtures cannot be included by PHP. And the container compilation fails.

A solution is to scan this directory only in when@dev.

services:
    _defaults:
        autowire: true
        autoconfigure: true

    App\:
        resource: '../src/'
        exclude: '../src/DataFixtures/'

when@dev:
    services:
        App\DataFixtures\:
            resource: '../src/DataFixtures/'

Using #[WhenNot(env: 'prod')] is not possible since the class cannot be loaded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions