문제

On my symfony app, the time has come to add mailer functionality. Im always aware that that some new functionality justifiably goes into its own bundle. right now i want to add some mailer functionality so a user can check off some options, then send the items to a friend.

thinking ahead, i might also use that functionality in another bundle in this same app, which is a different part of the website.

so im thinking, i might want to put an email controller in its own bundle, but i know the swiftmailer bundle is already doing this, which i will be using.

so in the end im thinking its probably only a few lines of code i will need, and that may be best placed on the controllers of the specific parts of the website i need the email functionality on.

now comes the main reason i thought of making it its own bundle, twig templates for the email body's. do i want these templates dangling around in my other bundles? i guess it would make sense.

any suggestions?

도움이 되었습니까?

해결책

It looks a bit overkill to create a bundle just for a few lines of code.

For your twig template you can put the shared template part inside app/Resources/views, which is shared for all your application. And put domain specific templates in domain specific bundles. http://symfony.com/doc/current/book/templating.html#template-naming-locations

Whatever your email logic code should be inside a service wrapping swift mailer, like that if you need to switch mailing strategy, for example sending mails using an HTTP API, you just need to change this service, not all your controllers.

If you have some code to share between your bundles, may should you have an {App|Main|Core|...}Bundle containing all your "Single" services, that can be moved later in their own bundle if needed.

Anyway their is many approach for your global question :

  • You could use a single bundle containing all your business logic and externalize / decouple your technical / generic stuff inside bundles that can be shared between your apps

  • You could have an opposite approach with one bundle for technical stuff and many bundles for your business logic, may could it be harder to keep it low coupled

  • Or a mix of both

In my point of view the first approach works nicely for simple applications while second and third can be more domain oriented for bigger apps. The most important is probably to be consistant.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top