Skip to content

Commit e785dc8

Browse files
committed
Decouple environment variable name from directory structure version (#84)
1 parent f404cd6 commit e785dc8

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/Configuration/DefaultConfiguration.php

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function __construct(string $localProjectDir)
7171
parent::__construct();
7272
$this->localProjectDir = $localProjectDir;
7373
$this->guessSymfonyDirectoryStructure(Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
74+
$this->setEnvironmentVarName(Kernel::MAJOR_VERSION);
7475
$this->setDefaultConfiguration();
7576
}
7677

@@ -372,22 +373,19 @@ public function setDefaultConfiguration(?int $symfonyDirectoryStructureVersion =
372373
}
373374

374375
if (self::SYMFONY_2 === $this->_symfonyDirectoryStructureVersion) {
375-
$this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
376376
$this->setDirs('app', 'app/config', 'app/cache', 'app/logs', 'src', 'app/Resources/views', 'web');
377377
$this->controllersToRemove(['web/app_*.php']);
378378
$this->sharedFiles = ['app/config/parameters.yml'];
379379
$this->sharedDirs = ['app/logs'];
380380
$this->writableDirs = ['app/cache/', 'app/logs/'];
381381
$this->dumpAsseticAssets = true;
382382
} elseif (self::SYMFONY_3 === $this->_symfonyDirectoryStructureVersion) {
383-
$this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
384383
$this->setDirs('bin', 'app/config', 'var/cache', 'var/logs', 'src', 'app/Resources/views', 'web');
385384
$this->controllersToRemove(['web/app_*.php']);
386385
$this->sharedFiles = ['app/config/parameters.yml'];
387386
$this->sharedDirs = ['var/logs'];
388387
$this->writableDirs = ['var/cache/', 'var/logs/'];
389388
} elseif (self::SYMFONY_4 === $this->_symfonyDirectoryStructureVersion) {
390-
$this->_symfonyEnvironmentEnvVarName = 'APP_ENV';
391389
$this->setDirs('bin', 'config', 'var/cache', 'var/log', 'src', 'templates', 'public');
392390
$this->controllersToRemove([]);
393391
$this->sharedDirs = ['var/log'];
@@ -402,6 +400,15 @@ protected function getReservedServerProperties(): array
402400
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];
403401
}
404402

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

424+
/**
425+
* Set the name of the environment variable for Symfony depending on the framework version
426+
*
427+
* @param int $symfonyMajorVersion
428+
*/
429+
private function setEnvironmentVarName(int $symfonyMajorVersion): void
430+
{
431+
if ($symfonyMajorVersion > 3) {
432+
$this->_symfonyEnvironmentEnvVarName = 'APP_ENV';
433+
} else {
434+
$this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
435+
}
436+
}
437+
417438
private function setDirs(string $binDir, string $configDir, string $cacheDir, string $logDir, string $srcDir, string $templatesDir, string $webDir): void
418439
{
419440
$this->binDir = $binDir;

0 commit comments

Comments
 (0)