How to integrate your existing Symfony application with Sulu CMS
The first thing you’ll need to know is you’ll be starting with the Sulu Skeleton and adding your application.
- Create a new sulu project using our Getting started Guide and omit the Git initialization
- Move the `.git` folder of your old project to the new sulu project (cp -r <your-old-project>/.git <your-new-sulu-project>/.git)
- Add your project files one by one into the new Sulu directory structure
- Commit the changes once everything is working (git will retain your history of your project files)
The most important thing you need to remember is: don’t create a new repository, but continue to work in the existing one. Git will do a fabulous job of retaining your project history.
Any potential issues to consider?
In theory, if you have multiple kernels in your application, this wouldn’t work. However, we haven’t come across it, because it’s pretty rare.
Another potential issue is that if you have your own skeleton, then you wouldn’t be able to do it this way. For example, with an application like Sylius, both systems try to take the leading role in the application. So you have to either integrate Sulu and Sylius as separate applications or put more effort into combining them as a single application.
What is the Sulu Skeleton?
So you might be wondering why you’d need to add your application to Sulu CMS, rather than the other way around. First, we should explain why the Skeleton exists.
Back in the day, we decided to use a setup with multiple kernels. It seemed like the right thing to do, because it allowed us to register certain bundles — including their services and configuration — only for the website or only for the administration interface. Having many services was a bigger issue in the past, because all of them were compiled into a single file that needed to be loaded. The more services you had, the bigger the resulting file was, and this file had to be loaded on every request. Since these services are now split among multiple files, this is not such a big issue anymore.
Another drawback of having a single kernel was that the Symfony firewall always started a HTTP session. That included the website, which would also have caused a performance impact and made caching the website harder. But Symfony has also solved this problem since then.
However, we still rely on having two kernels in some parts of our code, but Symfony 4 introduced Symfony Flex, a kind of package manager for Symfony which “enables distribution composition instead of inheritance,” as Fabien Potencier wrote in a Symfony 4 demo in 2017. This allows you to make use of Symfony Recipes to integrate third-party packages into Symfony applications. Symfony Flex will take care of the boring tasks like registering the bundle in the correct file and adding some basic configuration required by the bundle to work. These tedious tasks had to be done manually previously.
Now, if you start with the Sulu skeleton, you can use Symfony recipes, and cook up something awesome.
Speaking of recipes, check out this case study of a cool cooking website built in Sulu CMS: Küchengötter (“Gods Of The Kitchen”). OK — enough of the cooking metaphors!