Search code examples
phpsymfonydoctrine-ormcode-organization

Symfony2 applicaiton's with common code


I've have sf2 based api and admin apps, it's separated. But it uses one database. Now api works with database through doctrine entities and admin project is using native sql calls. And it's very annoying.

So my decision is to make common code reachable for 2 application. Mostly it will be doctrine entities.

Maybe someone have made something like that and have a good mechanizm. Ideas are welcome too.

For now I have only one idea, putt the entities in some other dir(synced with 3d repository) and config both projects to use it. But I can't get rid of thoughts that it can be made in simpler way.


Solution

  • A common and convenient way to share code between several applications is using Composer packages:

    • Extract the code of entities in a separate library and create a Composer package (if you want to make it private, create a private repository with Satis or Toran Proxy)
    • Install this new package in your admin and api apps.

    To be able to edit and commit code for your new private library directly in the vendor/ directory of your apps, use the --prefer-source flag when you run composer install or update.

    But here, you should ask yourself if it really make sense to have separate apps and repositories for the API and admin.