Skip to content

Commit

Permalink
Decouple environment variable name from directory structure version (#84
Browse files Browse the repository at this point in the history
)
  • Loading branch information
YetiCGN committed Jan 10, 2019
1 parent f404cd6 commit e785dc8
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions src/Configuration/DefaultConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function __construct(string $localProjectDir)
parent::__construct();
$this->localProjectDir = $localProjectDir;
$this->guessSymfonyDirectoryStructure(Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
$this->setEnvironmentVarName(Kernel::MAJOR_VERSION);
$this->setDefaultConfiguration();
}

Expand Down Expand Up @@ -372,22 +373,19 @@ public function setDefaultConfiguration(?int $symfonyDirectoryStructureVersion =
}

if (self::SYMFONY_2 === $this->_symfonyDirectoryStructureVersion) {
$this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
$this->setDirs('app', 'app/config', 'app/cache', 'app/logs', 'src', 'app/Resources/views', 'web');
$this->controllersToRemove(['web/app_*.php']);
$this->sharedFiles = ['app/config/parameters.yml'];
$this->sharedDirs = ['app/logs'];
$this->writableDirs = ['app/cache/', 'app/logs/'];
$this->dumpAsseticAssets = true;
} elseif (self::SYMFONY_3 === $this->_symfonyDirectoryStructureVersion) {
$this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
$this->setDirs('bin', 'app/config', 'var/cache', 'var/logs', 'src', 'app/Resources/views', 'web');
$this->controllersToRemove(['web/app_*.php']);
$this->sharedFiles = ['app/config/parameters.yml'];
$this->sharedDirs = ['var/logs'];
$this->writableDirs = ['var/cache/', 'var/logs/'];
} elseif (self::SYMFONY_4 === $this->_symfonyDirectoryStructureVersion) {
$this->_symfonyEnvironmentEnvVarName = 'APP_ENV';
$this->setDirs('bin', 'config', 'var/cache', 'var/log', 'src', 'templates', 'public');
$this->controllersToRemove([]);
$this->sharedDirs = ['var/log'];
Expand All @@ -402,6 +400,15 @@ protected function getReservedServerProperties(): array
return [Property::bin_dir, Property::config_dir, Property::console_bin, Property::cache_dir, Property::deploy_dir, Property::log_dir, Property::src_dir, Property::templates_dir, Property::web_dir];
}

/**
* Guess the directory structure of the project based on the framework version.
* Could be manually selected to a different structure on project setup, in that
* case the user should set the correct directory structure version in their
* deployment configuration.
*
* @param int $symfonyMajorVersion
* @param $symfonyMinorVersion
*/
private function guessSymfonyDirectoryStructure(int $symfonyMajorVersion, $symfonyMinorVersion): void
{
// TODO: Be a bit more clever and for example take composer.json extra configuration into account
Expand All @@ -414,6 +421,20 @@ private function guessSymfonyDirectoryStructure(int $symfonyMajorVersion, $symfo
}
}

/**
* Set the name of the environment variable for Symfony depending on the framework version
*
* @param int $symfonyMajorVersion
*/
private function setEnvironmentVarName(int $symfonyMajorVersion): void
{
if ($symfonyMajorVersion > 3) {
$this->_symfonyEnvironmentEnvVarName = 'APP_ENV';
} else {
$this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
}
}

private function setDirs(string $binDir, string $configDir, string $cacheDir, string $logDir, string $srcDir, string $templatesDir, string $webDir): void
{
$this->binDir = $binDir;
Expand Down

0 comments on commit e785dc8

Please sign in to comment.