-1

We are trying to run a couple of sites sharing about 90% of their code. The business domain is the same, but their UIs are a bit different. Hence they will have different CSS.

How would you manage the codebase to share the code that requires it?

XuDing
  • 1,982
  • 18
  • 27
  • Pardon me, but you have tagged your question as architecture. If everything is the same but UI whats the architectural question you have? Like how to `include()` relevant "shared" code bases? All this written currently is a question without enough context... – kayess Aug 03 '16 at 17:06
  • @close-voters This may sound broad, but is actually specific enough to be answered. Check [here](http://meta.stackoverflow.com/a/323828/576767). the tags concerned are different, but the principle is quite the same. Sharing code is a specific concern in regard of php ecosystem. – Félix Adriyel Gagnon-Grenier Aug 27 '16 at 02:13

1 Answers1

1

Two general ways

  • Structure the shared parts as Composer packages

For instance, all the application level code, such as router, dependency managing, validation, domain entities mapping can be managed as Composer dependencies through Packagist. It's possible to use private repos as dependencies if code is not open sourceable.

You would then have a different repo for each site, and make the parts which are the same be built using Composer, and only coding the part which is actually different. You'd probably have two servers, for different domains.

This implies more configuration through Composer and code.

repo 1
    /app
        /viewSpecificToOne
    /public
        /cssSpecificToOne
        /jsSpecificToOne
        index.php
    /vendor
        /[dependencies installed through composer]
repo 2
    /app
        /viewSpecificToTwo
    /public
        /cssSpecificToTwo
        /jsSpecificToTwo
        index.php
    /vendor
        /[dependencies installed through composer]
  • Manage all the sites from the same repo

This is close to the other solution, but you would send the different routes to different front Controllers, who would use the same domain mappers, validation, routers, etc. but have two different View layers, that would feature specific code.

This implies more configuration from the server to serve each domain from the two public repos.

Repo
    /app
        /view1
            /viewLogicSpecificToOne
        /view2
            /viewLogicSpecificToTwo
    /public1
        /cssSpecificToOne
        /jsSpecificToOne
        index.php
    /public2
        /cssSpecificToTwo
        /jsSpecificToTwo
        index.php
    /lib
        /sharedPackages