Where do I store services in Symfony2

I create an application in Symfony2 that receives an HTML string through an API, works on it (I think it’s something like a Tidy library, for a different purpose), and then returns the fixed HTML.

Everything that does all the work is mostly written in services because they do not need to return a Response object.

Where can I store these services? I put them in bundles, but there is no obvious place to store them. I understand that they can be stored anywhere, but I wonder what the default agreement is.

+4
source share
1 answer

If this code does not need to be reused outside of Symfony2 projects, you can simply put it in your package.

I would go for something like:

Acme\HtmlCleanerBundle\Cleaner\SimpleCleaner.php 

Since this is a package, you can extract it into a separate package and reuse it for other Symfony2 projects.

If you want the code to be completely reusable and standalone, I would suggest you extract it into a separate library. You still have dependencies on individual components (shameless plugin: you can manage these dependencies through composer , which will be used by Symfony 2.1).

If you decide to go this route, the package simply integrates the library into Symfony2, providing it with a DI container configuration.

+7
source

Source: https://habr.com/ru/post/1401564/


All Articles