Skip to content

feat(metadata): resolve %param% in yaml/xml and attribute resource config - #8284

Open
soyuka wants to merge 1 commit into
api-platform:mainfrom
soyuka:feat/attributes-resolve-container-params
Open

feat(metadata): resolve %param% in yaml/xml and attribute resource config#8284
soyuka wants to merge 1 commit into
api-platform:mainfrom
soyuka:feat/attributes-resolve-container-params

Conversation

@soyuka

@soyuka soyuka commented Jun 10, 2026

Copy link
Copy Markdown
Member

What

Resolves Symfony container parameters (%param%) in resource configuration regardless of the source — YAML, XML and PHP attributes. Consolidates and supersedes the YAML/XML-only #8282; the whole thing ships as one feature targeting main.

Closes #8104.

Why

%param% previously only resolved for the resource class key. Scalar fields went through verbatim, and attribute values — being raw PHP literals — reached ExpressionLanguage as %param% and threw Unexpected token "operator" of value "%". The reporter's security: '%param%' is the canonical case.

How

  • ContainerParameterResolver (src/Metadata/Util/) — DI-free (PSR ContainerInterface), reuses Symfony's router regex (/%%|%([^%\s]++)%/, %% escapes a literal %, env() forbidden, arrays resolved recursively). The metadata component gains no symfony/dependency-injection dependency.
  • YAML/XMLAbstractResourceExtractor now delegates to the shared resolver (the duplicated router logic is removed); phpize() resolves scalar strings, expression fields opt out and route through resolveExpressionPlaceholder().
  • Attributes — a Symfony-bridge decorator ContainerParameterResourceMetadataCollectionFactory walks each resource + operation and substitutes via the immutable with*() setters.

Resolution rules (uniform across sources)

  • Scalar fields — substitution anywhere: shortName, description, uriTemplate, routePrefix, routeName, host, controller, securityMessage, securityPostDenormalizeMessage, securityPostValidationMessage, provider, processor.
  • ExpressionLanguage fields — whole-string %param% only (^%[^%\s]+%$): security, securityPostDenormalize, securityPostValidation, condition. A bare %param% is invalid ExpressionLanguage, so resolving it can't break a working expression; partial % and real modulo (object.value % 2) reach the engine verbatim.
  • Excluded: class (resource identity) and array/context fields (normalizationContext, defaults, requirements, filters …).

BC

Purely additive — %param% in these positions previously threw or was ignored, so no working configuration changes behavior.

Tests

  • Extractor unit tests (YAML + XML): scalar resolves, whole-string security resolves, real expression untouched.
  • Decorator unit test (attributes): same matrix.
  • Functional ApiTestCase ×2 — a YAML-config resource and an attribute-defined resource, both security: '%param%' → ROLE_ADMIN 200 / ROLE_USER 403 / anonymous 401.

@soyuka
soyuka force-pushed the feat/attributes-resolve-container-params branch from d45ee70 to 49a249d Compare June 10, 2026 12:45
@soyuka soyuka changed the title feat(metadata): resolve %param% in attribute resource config feat(metadata): resolve %param% in yaml/xml and attribute resource config Jun 10, 2026
@soyuka
soyuka force-pushed the feat/attributes-resolve-container-params branch 2 times, most recently from a99cf97 to 2f4d70f Compare September 12, 2026 05:35
Resolve container parameters in YAML, XML, and PHP attribute resource
metadata. Include GraphQL operations when resolving attribute metadata.

Closes api-platform#8104
@soyuka
soyuka force-pushed the feat/attributes-resolve-container-params branch from 2f4d70f to 4a16a39 Compare September 12, 2026 07:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Yaml resource configs with Symfony parameters doesn't work

1 participant