Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit f3ffcdd

Browse files
authored
Merge pull request #5 from fd6130/patch
Fix Symfony 3.4 default directory issue
2 parents 6ce1264 + e2814d2 commit f3ffcdd

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed

src/Configuration/DefaultConfiguration.php

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@
2323
*/
2424
final class DefaultConfiguration extends AbstractConfiguration
2525
{
26+
const SYMFONY_2 = 2;
27+
const SYMFONY_3 = 3;
28+
const SYMFONY_4 = 4;
29+
const SYMFONY_5 = 5;
30+
2631
// variables starting with an underscore are for internal use only
2732
private $_symfonyEnvironmentEnvVarName; // SYMFONY_ENV or APP_ENV
2833

@@ -65,7 +70,7 @@ public function __construct(string $localProjectDir)
6570
{
6671
parent::__construct();
6772
$this->localProjectDir = $localProjectDir;
68-
$this->setDefaultConfiguration(Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
73+
$this->setDefaultConfiguration(Kernel::MAJOR_VERSION);
6974
}
7075

7176
// this proxy method is needed because the autocompletion breaks
@@ -368,30 +373,50 @@ protected function getReservedServerProperties(): array
368373
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];
369374
}
370375

371-
private function setDefaultConfiguration(int $symfonyMajorVersion, $symfonyMinorVersion): void
376+
private function setDefaultConfiguration(int $symfonyMajorVersion): self
372377
{
373-
if (2 === $symfonyMajorVersion) {
374-
$this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
378+
if(self::SYMFONY_2 > $symfonyMajorVersion || self::SYMFONY_5 < $symfonyMajorVersion)
379+
{
380+
throw new \InvalidArgumentException("%d is not a supported Symfony version.", $symfonyMajorVersion);
381+
}
382+
383+
$this->setEnvironmentVarName($symfonyMajorVersion);
384+
385+
if (self::SYMFONY_2 === $symfonyMajorVersion) {
375386
$this->setDirs('app', 'app/config', 'app/cache', 'app/logs', 'src', 'app/Resources/views', 'web');
376387
$this->controllersToRemove(['web/app_*.php']);
377388
$this->sharedFiles = ['app/config/parameters.yml'];
378389
$this->sharedDirs = ['app/logs'];
379390
$this->writableDirs = ['app/cache/', 'app/logs/'];
380391
$this->dumpAsseticAssets = true;
381-
} elseif (3 === $symfonyMajorVersion && 4 < $symfonyMinorVersion) {
382-
$this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
392+
} elseif (self::SYMFONY_3 === $symfonyMajorVersion) {
383393
$this->setDirs('bin', 'app/config', 'var/cache', 'var/logs', 'src', 'app/Resources/views', 'web');
384394
$this->controllersToRemove(['web/app_*.php']);
385395
$this->sharedFiles = ['app/config/parameters.yml'];
386396
$this->sharedDirs = ['var/logs'];
387397
$this->writableDirs = ['var/cache/', 'var/logs/'];
388-
} elseif (4 <= $symfonyMajorVersion || (3 === $symfonyMajorVersion && 4 >= $symfonyMinorVersion)) {
389-
$this->_symfonyEnvironmentEnvVarName = 'APP_ENV';
398+
} elseif (self::SYMFONY_4 <= $symfonyMajorVersion) { // support Symfony 4 or above
390399
$this->setDirs('bin', 'config', 'var/cache', 'var/log', 'src', 'templates', 'public');
391400
$this->controllersToRemove([]);
392401
$this->sharedDirs = ['var/log'];
393402
$this->writableDirs = ['var/cache/', 'var/log/'];
394403
}
404+
405+
return $this;
406+
}
407+
408+
/**
409+
* Set the name of the environment variable for Symfony depending on the framework version
410+
*
411+
* @param int $symfonyMajorVersion
412+
*/
413+
private function setEnvironmentVarName(int $symfonyMajorVersion): void
414+
{
415+
if ($symfonyMajorVersion > 3) {
416+
$this->_symfonyEnvironmentEnvVarName = 'APP_ENV';
417+
} else {
418+
$this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
419+
}
395420
}
396421

397422
private function setDirs(string $binDir, string $configDir, string $cacheDir, string $logDir, string $srcDir, string $templatesDir, string $webDir): void

0 commit comments

Comments
 (0)