feat(config): add configuration tree and migrate to AbstractBundle#85
Merged
Merged
Conversation
Migrate the bundle to the modern layout: the bundle class extends AbstractBundle, defines the api_platform_translation configuration tree in configure() and imports root-level config/services.php (PHP DSL) from loadExtension(). The legacy ApiPlatformTranslationExtension keeps working standalone but is deprecated for removal in 3.0. New configuration, all defaults preserving current behavior: - enabled_locales: accepted request locales, empty inherits framework.enabled_locales - fallback_locale: locale stamped as fallback on translatables, null inherits kernel.default_locale - locale_resolution: ordered locale sources (query_param, accept_language), each can be removed or reordered Translator resolves the locale by iterating the configured sources. A request without an Accept-Language header now falls through to the next source instead of resolving to the head of the negotiation list, which is what makes non-default orders meaningful; with the default order the observable behavior is unchanged. Dependency hygiene: symfony/config, symfony/http-kernel and symfony/deprecation-contracts are now direct requirements, symfony/yaml is dropped (no YAML is loaded at runtime anymore).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The bundle still uses the legacy layout (
src/Resources/config/services.yml, a hand-writtenExtensionclass) and has no configuration tree at all: locale restriction is only inherited fromframework.enabled_locales, the fallback locale stamped on translatables is hard-wired tokernel.default_locale, and the locale resolution order (query parameter, thenAccept-Language) cannot be changed or partially disabled. Upcoming behavioral options (such as opt-in translation auto-creation) need a place to live.Changes
AbstractBundle:configure()defines theapi_platform_translationconfiguration tree,loadExtension()sets thelocastic_api_platform_translation.*parameters and imports the services file. This is the documented recommended setup for new bundles. The extension alias is pinned explicitly and guarded by a test, since the config key is public API.enabled_locales(empty inheritsframework.enabled_locales),fallback_locale(null inheritskernel.default_locale),locale_resolution(orderedquery_param/accept_languagesources, each removable, duplicates rejected).config/services.php(PHP DSL) at the bundle root andsrc/Resources/removed;AbstractBundle's defaultgetPath()already resolves the modern layout, so no override is needed. Service IDs, tags and thetranslation.groupsfilter id are unchanged; a FQCN alias forTranslatorwas added so it can be autowired by type.ApiPlatformTranslationExtensionis deprecated for removal in 3.0 but keeps working standalone (it now loads the PHP services file and sets the parameters itself), so the minor stays BC-clean; documented in UPGRADE-2.1.md.Translator::loadCurrentLocale()iterates the configured sources. Surprising but deliberate: a request without anAccept-Languageheader now falls through to the next source instead of resolving to the head of the negotiation list, which is what makes non-default orders like[accept_language, query_param]meaningful. With the default order the observable behavior is identical (covered by the existing test rows). An explicit but not-enabled locale still pins the default instead of falling through.symfony/config,symfony/http-kernelandsymfony/deprecation-contractsare now direct requirements (all used directly),symfony/yamlis dropped since no YAML is loaded at runtime anymore.TestKernelaccepts per-test bundle and framework config (hashed into the cache dir so container caches never collide) and points its app-level config dir into the cache dir, because Symfony 8.1 debug kernels dump aconfig/reference.phpinto the project config dir, which is now a real bundle directory.Verification
bin/phpunit: 82 tests, 166 assertions, green (9 pre-existing PHPUnit deprecations from legacy non-static data providers, count unchanged). New coverage: functional kernel tests for defaults, framework inheritance, bundle overrides, resolution-order wiring and rejection of unknown or duplicate sources; unit tests for every resolution order variant; a legacy-extension standalone test; an extension-alias stability test.bin/phpstan analyse(level 6, now also coveringconfig/): no errors.bin/php-cs-fixer fix --dry-run(now also coveringconfig/): clean.composer validate --strict: valid.AbstractBundlesource for thegetPath()behavior on the oldest supported Symfony.translation-demo(Symfony 7.4, API Platform 4.3, sqlite):composer updateof the bundle resolves the new constraints and the container compiles; with no bundle config, all six baseline resolution cases behave exactly like 2.0 (query param, header negotiation with q-values, query beating header, non-enabled locale pinning the default); withenabled_locales: [en, de, hr],fallback_locale: de,locale_resolution: [accept_language]the query parameter is ignored, the header wins, and a request forhr(enabled, no translation) falls back to the German translation, proving thefallback_localewiring;locale_resolution: [cookie]and duplicate sources fail the container build with the expected messages; PATCH adding a translation still works (denormalizer wired through the new services file).translation-demo-ap34(API Platform 3.4): container compiles, POST with nested translations,?locale=,Accept-Languageand thegroups[]=translationsfilter (the ChildDefinition ofapi_platform.serializer.group_filter) all behave correctly.