KnpLabs / DoctrineBehaviors

Doctrine2 behavior traits that help handling Blameable, Loggable, Sluggable, SoftDeletable, Uuidable, Timestampable, Translatable, Tree behavior
http://knplabs.com
MIT License
911 stars 287 forks source link

Use best practices for service registration #659

Closed franmomu closed 2 years ago

franmomu commented 2 years ago

Following https://symfony.com/doc/current/bundles/best_practices.html#services:

If the bundle defines services, they must be prefixed with the bundle alias instead of using fully qualified class names like you do in your project services. For example, AcmeBlogBundle services must be prefixed with acme_blog. The reason is that bundles shouldn’t rely on features such as service autowiring or autoconfiguration to not impose an overhead when compiling application services.

In addition, services not meant to be used by the application directly, should be defined as private. For public services, aliases should be created from the interface/class to the service id. For example, in MonologBundle, an alias is created from Psr\Log\LoggerInterface to logger so that the LoggerInterface type-hint can be used for autowiring.

Services should not use autowiring or autoconfiguration. Instead, all services should be defined explicitly.

It would be nice to follow these practices in:

https://github.com/KnpLabs/DoctrineBehaviors/blob/16cf5617882d4e5828215f2018cb58b3d24c0ee7/config/services.php#L17-L20

I could give it a try if this is fine, the only problem I see is that UserProvider is using:

https://github.com/KnpLabs/DoctrineBehaviors/blob/16cf5617882d4e5828215f2018cb58b3d24c0ee7/src/Provider/UserProvider.php#L12-L16

~Security which is registered by symfony/security-bundle which is not a dependency (BTW looks like security.token_storage could be used instead).~ I would leave the Security service as it is for now.

franmomu commented 2 years ago

Closing here, see https://github.com/KnpLabs/DoctrineBehaviors/pull/660#issuecomment-917385552