Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Config] Fix array shape generation for backed enums#62563

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
OskarStark wants to merge3 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromOskarStark:fix/backend-enums

Conversation

@OskarStark
Copy link
Contributor

@OskarStarkOskarStark commentedNov 29, 2025
edited
Loading

QA
Branch?7.4
Bug fix?yes
New feature?no
Deprecations?no
Issues--
LicenseMIT

Spotted insymfony/ai#1013 ➡️https://github.com/symfony/ai/actions/runs/19780810683/job/56680686767?pr=1013

It works forredis, but not forpostgres, becauseredis is using->values(Distance::cases()) andpostgres is using->enumFqcn(PostgresDistance::class):

Redis

Enum

enum Distance:string{use Comparable;case Cosine ='COSINE';caseL2 ='L2';case Ip ='IP';}

Config

->enumNode('distance')    ->info('Distance metric to use for vector similarity search')    ->values(Distance::cases())    ->defaultValue(Distance::Cosine)->end()

RESULT

 *         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

enum Distance:string{use Comparable;case Cosine ='cosine';case InnerProduct ='inner_product';caseL1 ='l1';caseL2 ='l2';publicfunctiongetComparisonSign():string    {returnmatch ($this) {self::Cosine =>'<=>',self::InnerProduct =>'<#>',self::L1 =>'<+>',self::L2 =>'<->',        };    }}

Config

->enumNode('distance')    ->info('Distance metric to use for vector similarity search')    ->enumFqcn(PostgresDistance::class)    ->defaultValue(PostgresDistance::L2)->end()

RESULT

 *         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?

$values =array_column($enumFqcn::cases(),'value');

returnimplode('|',array_map(staticfunction ($value) {
return\is_string($value) ?'"'.$value.'"' :$value;
Copy link
Contributor

@ging-devging-devNov 29, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Suggested change
return\is_string($value) ?'"'.$value.'"' :$value;
return\is_string($value) ?var_export($value,true) :$value;

"test will become""test"," must be escape, so i thinkvar_export is good solution for it, but it using' to wrap string, or maybeaddslashes($value, '"') but i dont really like it

Ref:https://phpstan.org/r/924d234a-ce8c-46e4-9374-ff940704394d

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

updated

ging-dev reacted with thumbs up emoji
case Foo ='foo';
case Bar ='bar';
case Bar ='bar baz';
case Qux ='"test"';
Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Not sure if should check for such edgecase

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@alexandre-dauboisalexandre-dauboisAwaiting requested review from alexandre-daubois

@chr-hertelchr-hertelAwaiting requested review from chr-hertel

1 more reviewer

@ging-devging-devging-dev left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

7.4

Development

Successfully merging this pull request may close these issues.

3 participants

@OskarStark@ging-dev@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp