Symfony application with multiple instances with a common codebase

So I'm overwriting a large set of SAAS web applications on top of Symfony 3. What started with 10-20 applications has now grown to over 500 applications. The app-only vendor directory is 150+ MB.

All of these applications have their own database. I would like to keep it that way. However, I believe it would be nice if some code was shared. Take vendor directory and src for example. This is the same for every application, but they are all "loaded" separately into OpCache. I believe that in terms of resources, it would be better if these directories were separated.

Both Composer and Symfony do not really support multi-user applications with shared directories. I was wondering, however, if anyone has a key to achieving what I had in mind, or that my plan is simply not possible?

The configuration is different for each application (parameters.yml) and the web directory contains different stylesheets for each application. Therefore, they must be separated from the rest.

I've been thinking about using an environment setting for this, but it doesn't feel good that we have an environment "test", "dev", "application1", "application2", etc. config_prod.yml suddenly also becomes unusable then.

Is my way of thinking wrong? Any suggestions on how to achieve this? Or should I just go with full individual instances?

(Our application uses SemVer, and it would be nice if we had common code for version 1.0.0., Version 1.1.0, etc. So even the next layer on top. But maybe this is the next step.)

edit: To clarify a little more; In essence, you can say that the var directory and the var directory are not simultaneously accessible. The web directory contains custom style sheets and is the main entry point. The var directory contains cache files which are different for each application depending on the database settings. Finally, you also have a custom settings file, which is different for each application, for storing database credentials.

I've tried symlinking, but the composer isn't really very happy with it. Also, when using symbolic links, the working directory is always the real directory in use, not the actual directory you are linked to. I've also tried with custom settings in the application vhost file. It is possible to override the cache and kernel directories, but again you lose the actual directory you are linking to.

+3


source to share


1 answer


You will need to create custom config directories and / or files and then customize AppKernel

to point to the correct one based on whatever criteria you use. For example, if you selected a subdomain: First, update your external controller to have a new super global. There is probably a better way to do this, and I would recommend looking into it.

// web/app.php
use Symfony\Component\HttpFoundation\Request;

/** @var \Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/../app/autoload.php';
include_once __DIR__.'/../var/bootstrap.php.cache';

list($scheme, $host) = explode('.',$_SERVER['SERVER_NAME']);
define(APP_CONFIG_FILENAME, sprintf('%s.yml', $host));

$kernel = new AppKernel('prod', false);
$kernel->loadClassCache();
//$kernel = new AppCache($kernel);

// When using the HttpCache, you need to call the method in your front controller instead of relying on the configuration parameter
//Request::enableHttpMethodParameterOverride();
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

      

Now in yours AppKernel

use this new superglobal



// app/AppKernel.php
use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;

class AppKernel extends Kernel
{
    public function registerContainerConfiguration(LoaderInterface $loader)
    {
        $loader->load($this->getProjectDir().'/app/config/' . APP_CONFIG_FILENAME . '.yml');
    }
}

      

And then in your example1.yml

# app/config/mysubdomain.yml
imports:
    - { resource: 'parameters_example1.yml' }
    - { resource: 'routing_example1.yml' }

      

0


source







All Articles