Skip to content

Conversation

@nicolas-grekas
Copy link
Member

Q A
Branch? 7.4
Bug fix? no
New feature? no
Deprecations? no
Issues -
License MIT

A subset of #58771

Note that only constructors get the array-shape as that's what we're going to need first to achieve what we target in #58771. We could also add array shapes to the generated fluent methods. I left that as an exercise to a future contributor ;)

@alexandre-daubois
Copy link
Member

Comments addressed in 07aa0c8.

I used | as the delimiter for the generated info/deprecation/default value. I also hesitated to use / maybe.

@alexandre-daubois
Copy link
Member

alexandre-daubois commented Sep 29, 2025

New review addressed in 0bf17d2 (comments refactoring, nullable prototyped arrays et al)

@nicolas-grekas
Copy link
Member Author

Thank you @alexandre-daubois.

@nicolas-grekas nicolas-grekas merged commit b68f0e6 into symfony:7.4 Sep 29, 2025
11 of 12 checks passed
nicolas-grekas added a commit that referenced this pull request Sep 29, 2025
…ig-builders from config files (nicolas-grekas)

This PR was merged into the 7.4 branch.

Discussion
----------

[DependencyInjection] Handle returning arrays and config-builders from config files

| Q             | A
| ------------- | ---
| Branch?       | 7.4
| Bug fix?      | no
| New feature?  | yes
| Deprecations? | no
| Issues        | -
| License       | MIT

Another step on the path explored in #58771

This allows returning PHP arrays or config-builders from config files.

Several styles are supported, some examples below.

What this does *not* support is config trees under the `import`, `parameters` or `services` namespaces (that's for another PR).

Arrays:
```php
return [
    'framework' => [...],
];
```

```php
return static function () {
    yield 'framework' => [...];
];
```

Config builders (best DX together with #61879):

```php
return new FrameworkConfig([...]);
```

```php
return static function () {
    return new FrameworkConfig([...]);
];
```

```php
// $env is always available in config files
if ('dev' === $env) {
    return new FrameworkConfig([...]);
}
```

```php
return static function (string $env) {
    if ('dev' === $env) {
        yield new FrameworkConfig([...]);
    }
};
```

Commits
-------

ff3fbd7 [DependencyInjection] Handle returning arrays and config-builders from config files
@nicolas-grekas nicolas-grekas deleted the generate-array-shapes branch September 29, 2025 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants