|
23 | 23 | */ |
24 | 24 | final class DefaultConfiguration extends AbstractConfiguration |
25 | 25 | { |
| 26 | + const SYMFONY_2 = 2; |
| 27 | + const SYMFONY_3 = 3; |
| 28 | + const SYMFONY_4 = 4; |
| 29 | + const SYMFONY_5 = 5; |
| 30 | + |
26 | 31 | // variables starting with an underscore are for internal use only |
27 | 32 | private $_symfonyEnvironmentEnvVarName; // SYMFONY_ENV or APP_ENV |
28 | 33 |
|
@@ -65,7 +70,7 @@ public function __construct(string $localProjectDir) |
65 | 70 | { |
66 | 71 | parent::__construct(); |
67 | 72 | $this->localProjectDir = $localProjectDir; |
68 | | - $this->setDefaultConfiguration(Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION); |
| 73 | + $this->setDefaultConfiguration(Kernel::MAJOR_VERSION); |
69 | 74 | } |
70 | 75 |
|
71 | 76 | // this proxy method is needed because the autocompletion breaks |
@@ -368,30 +373,50 @@ protected function getReservedServerProperties(): array |
368 | 373 | 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]; |
369 | 374 | } |
370 | 375 |
|
371 | | - private function setDefaultConfiguration(int $symfonyMajorVersion, $symfonyMinorVersion): void |
| 376 | + private function setDefaultConfiguration(int $symfonyMajorVersion): self |
372 | 377 | { |
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) { |
375 | 386 | $this->setDirs('app', 'app/config', 'app/cache', 'app/logs', 'src', 'app/Resources/views', 'web'); |
376 | 387 | $this->controllersToRemove(['web/app_*.php']); |
377 | 388 | $this->sharedFiles = ['app/config/parameters.yml']; |
378 | 389 | $this->sharedDirs = ['app/logs']; |
379 | 390 | $this->writableDirs = ['app/cache/', 'app/logs/']; |
380 | 391 | $this->dumpAsseticAssets = true; |
381 | | - } elseif (3 === $symfonyMajorVersion && 4 < $symfonyMinorVersion) { |
382 | | - $this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV'; |
| 392 | + } elseif (self::SYMFONY_3 === $symfonyMajorVersion) { |
383 | 393 | $this->setDirs('bin', 'app/config', 'var/cache', 'var/logs', 'src', 'app/Resources/views', 'web'); |
384 | 394 | $this->controllersToRemove(['web/app_*.php']); |
385 | 395 | $this->sharedFiles = ['app/config/parameters.yml']; |
386 | 396 | $this->sharedDirs = ['var/logs']; |
387 | 397 | $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 |
390 | 399 | $this->setDirs('bin', 'config', 'var/cache', 'var/log', 'src', 'templates', 'public'); |
391 | 400 | $this->controllersToRemove([]); |
392 | 401 | $this->sharedDirs = ['var/log']; |
393 | 402 | $this->writableDirs = ['var/cache/', 'var/log/']; |
394 | 403 | } |
| 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 | + } |
395 | 420 | } |
396 | 421 |
|
397 | 422 | private function setDirs(string $binDir, string $configDir, string $cacheDir, string $logDir, string $srcDir, string $templatesDir, string $webDir): void |
|
0 commit comments