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

[FrameworkBundle][Serializer] Allow setting$objectClassResolver via configuration#60092

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
HypeMC wants to merge1 commit intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromHypeMC:allow-setting-object-class-resolver

Conversation

HypeMC
Copy link
Member

QA
Branch?7.3
Bug fix?no
New feature?yes
Deprecations?no
IssuesFix#58526
LicenseMIT

Currently, theMaxDepth feature doesn't work correctly with Doctrine proxies because theisMaxDepthReached method relies on the object's class:

privatefunctionisMaxDepthReached(array$attributesMetadata,string$class,string$attribute,array &$context):bool
{
if (!($enableMaxDepth =$context[self::ENABLE_MAX_DEPTH] ??$this->defaultContext[self::ENABLE_MAX_DEPTH] ??false)
|| !isset($attributesMetadata[$attribute]) ||null ===$maxDepth =$attributesMetadata[$attribute]?->getMaxDepth()
) {
returnfalse;
}
$key =\sprintf(self::DEPTH_KEY_PATTERN,$class,$attribute);
if (!isset($context[$key])) {
$context[$key] =1;
returnfalse;
}
if ($context[$key] ===$maxDepth) {
returntrue;
}
++$context[$key];
returnfalse;
}

This class is determined usingget_class(), which returns a different result for proxy and non-proxy objects:

$this->objectClassResolver = ($objectClassResolver ??'get_class')(...);

Both theObjectNormalizer andPropertyNormalizer have a$objectClassResolver property, but there is currently no way to configure it.

This PR introduces a new configuration option to set the$objectClassResolver. You can provide either a callable or a service:

Using a callable:

framework:serializer:object_class_resolver:[ 'Doctrine\ORM\Proxy\DefaultProxyClassNameResolver', 'getClass' ]

Using a service:

services:app.object_class_resolver:class:Closurefrom_callable:[ !service { class: 'Doctrine\ORM\Proxy\DefaultProxyClassNameResolver' }, 'getClass' ]framework:serializer:object_class_resolver:app.object_class_resolver

@HypeMCHypeMC requested a review fromdunglas as acode ownerMarch 31, 2025 01:10
@carsonbotcarsonbot added this to the7.3 milestoneMar 31, 2025
@carsonbotcarsonbot changed the title[Serializer][FrameworkBundle] Allow setting$objectClassResolver via configuration[FrameworkBundle][Serializer] Allow setting$objectClassResolver via configurationMar 31, 2025
@HypeMCHypeMCforce-pushed theallow-setting-object-class-resolver branch fromf737ffb tob20009cCompareMarch 31, 2025 01:12
if (!($enableMaxDepth = $context[self::ENABLE_MAX_DEPTH] ?? $this->defaultContext[self::ENABLE_MAX_DEPTH] ?? false)
if (!($context[self::ENABLE_MAX_DEPTH] ?? $this->defaultContext[self::ENABLE_MAX_DEPTH] ?? false)
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Not used.

Copy link
Member

@nicolas-grekasnicolas-grekas left a comment

Choose a reason for hiding this comment

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

IIUC, this means everybody using the Serializer with Doctrine entities will need this, isn't it?
Shouldn't we patch DoctrineBundle instead so that there's nothing to configure on the user side?

kaznovac reacted with thumbs up emoji
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@nicolas-grekasnicolas-grekasnicolas-grekas left review comments

@dunglasdunglasAwaiting requested review from dunglasdunglas is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

Serializer "max_depth" of 1 goes 2 levels deep when encountering a Doctrine Proxy class
4 participants
@HypeMC@nicolas-grekas@fabpot@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp