Search code examples
phpsymfonyfosoauthserverbundle

Does ".default" have any special significance in Symfony service IDs?


I'm looking at some service definitions in FriendsOfSymfony/FOSOAuthServerBundle and it stood out to me that there's a definition for fos_oauth_server.storage.default, but another service in the same file lists fos_oauth_server.storage, without the .default part, as a dependency. Is there some kind of wildcard thing going on here, or...? This is something the Symfony documentation isn't particularly clear about.


Solution

  • The id fos_oauth_server.storage is an alias pointing to a storage service, by default fos_oath_server.storage.default. In your application's config you can replace this storage with a custom service as can be seen in the bundle's Configuration or the Configuration reference in the docs. Inside the Bundle's Extension-class you can see how the app configuration is wired into the bundle's service configuration and that the alias points to the configured service (either default or your own).

    All services requiring an oauth storage (including the classes in your application) should only reference the alias, so that the underlying (default) storage can easily be replaced without touching the code that is using it.

    The concept is widely used in bundles and the naming convention for the underlying service varies. Another common naming scheme, especially if there are multiple options that can be configured, is appending what type of service it is, e.g fos_oauth_server.storage.mysql, fos_oauth_server.storage.redis and so on. Aside from being a way to better distinguish the alias and the concrete implementations that the alias can point to there is no special significance to .default in Symfony.