Commit 2c32330
committed
bug #62563 [Config] Fix array shape generation for backed enums (OskarStark)
This PR was squashed before being merged into the 7.4 branch.
Discussion
----------
[Config] Fix array shape generation for backed enums
| Q | A
| ------------- | ---
| Branch? | 7.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | --
| License | MIT
Spotted in symfony/ai#1013 ➡️ https://github.com/symfony/ai/actions/runs/19780810683/job/56680686767?pr=1013
It works for `redis`, but not for `postgres`, because `redis` is using `->values(Distance::cases())` and `postgres` is using `->enumFqcn(PostgresDistance::class)`:
### Redis
#### Enum
```php
enum Distance: string
{
use Comparable;
case Cosine = 'COSINE';
case L2 = 'L2';
case Ip = 'IP';
}
```
#### Config
```php
->enumNode('distance')
->info('Distance metric to use for vector similarity search')
->values(Distance::cases())
->defaultValue(Distance::Cosine)
->end()
```
#### RESULT
```php
* redis?: array<string, array{ // Default: []
* connection_parameters?: mixed, // see https://github.com/phpredis/phpredis?tab=readme-ov-file#example-1
* client?: string, // a service id of a Redis client
* index_name: string,
* key_prefix?: string, // Default: "vector:"
* distance?: \Symfony\AI\Store\Bridge\Redis\Distance::Cosine|\Symfony\AI\Store\Bridge\Redis\Distance::L2|\Symfony\AI\Store\Bridge\Redis\Distance::Ip, // Distance metric to use for vector similarity search // Default: "COSINE"
* }>,
```
### Postgres
#### Enum
```php
enum Distance: string
{
use Comparable;
case Cosine = 'cosine';
case InnerProduct = 'inner_product';
case L1 = 'l1';
case L2 = 'l2';
public function getComparisonSign(): string
{
return match ($this) {
self::Cosine => '<=>',
self::InnerProduct => '<#>',
self::L1 => '<+>',
self::L2 => '<->',
};
}
}
```
#### Config
```php
->enumNode('distance')
->info('Distance metric to use for vector similarity search')
->enumFqcn(PostgresDistance::class)
->defaultValue(PostgresDistance::L2)
->end()
```
#### RESULT
```php
* postgres?: array<string, array{ // Default: []
* dsn?: string,
* username?: string,
* password?: string,
* table_name: string,
* vector_field?: string,
* distance?: cosine|inner_product|l1|l2, // Distance metric to use for vector similarity search // Default: "l2"
* dbal_connection?: string,
* }>,
```
you can see, that the result is different:
FQCN:
`distance?: \Symfony\AI\Store\Bridge\Redis\Distance::Cosine|\Symfony\AI\Store\Bridge\Redis\Distance::L2|\Symfony\AI\Store\Bridge\Redis\Distance::Ip,`
vs. strings:
`distance?: cosine|inner_product|l1|l2,`
Why?
Commits
-------
62422c43483 [Config] Fix array shape generation for backed enumsFile tree
7 files changed
+18
-8
lines changed- Definition
- Tests
- Builder/Fixtures/PrimitiveTypes/Symfony/Config
- Definition
- Dumper
- Fixtures
7 files changed
+18
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
83 | 89 | | |
84 | 90 | | |
85 | 91 | | |
86 | 92 | | |
87 | | - | |
| 93 | + | |
88 | 94 | | |
89 | 95 | | |
90 | 96 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
28 | 30 | | |
29 | 31 | | |
30 | 32 | | |
| |||
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| 57 | + | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
| 45 | + | |
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
102 | 102 | | |
103 | 103 | | |
104 | 104 | | |
105 | | - | |
| 105 | + | |
106 | 106 | | |
107 | 107 | | |
108 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
138 | 138 | | |
139 | 139 | | |
140 | 140 | | |
141 | | - | |
| 141 | + | |
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
| 8 | + | |
9 | 9 | | |
0 commit comments