|
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 | + |
26 | 30 | // variables starting with an underscore are for internal use only
|
27 | 31 | private $_symfonyEnvironmentEnvVarName; // SYMFONY_ENV or APP_ENV
|
| 32 | + private $_symfonyDirectoryStructureVersion; |
28 | 33 |
|
29 | 34 | // properties are defined as private so the developer doesn't see them when using
|
30 | 35 | // their IDE autocompletion. To simplify things, the builder defines setter
|
@@ -65,7 +70,8 @@ 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->guessSymfonyDirectoryStructure(Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION); |
| 74 | + $this->setDefaultConfiguration(); |
69 | 75 | }
|
70 | 76 |
|
71 | 77 | // this proxy method is needed because the autocompletion breaks
|
@@ -364,24 +370,42 @@ protected function getReservedServerProperties(): array
|
364 | 370 | 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];
|
365 | 371 | }
|
366 | 372 |
|
367 |
| - private function setDefaultConfiguration(int $symfonyMajorVersion, $symfonyMinorVersion): void |
| 373 | + private function guessSymfonyDirectoryStructure(int $symfonyMajorVersion, $symfonyMinorVersion): void |
368 | 374 | {
|
369 | 375 | if (2 === $symfonyMajorVersion) {
|
| 376 | + $this->_symfonyDirectoryStructureVersion = self::SYMFONY_2; |
| 377 | + } elseif (3 === $symfonyMajorVersion && 4 < $symfonyMinorVersion) { |
| 378 | + $this->_symfonyDirectoryStructureVersion = self::SYMFONY_3; |
| 379 | + } elseif (4 === $symfonyMajorVersion || (3 === $symfonyMajorVersion && 4 >= $symfonyMinorVersion)) { |
| 380 | + $this->_symfonyDirectoryStructureVersion = self::SYMFONY_4; |
| 381 | + } |
| 382 | + } |
| 383 | + |
| 384 | + public function setDefaultConfiguration(?int $symfonyDirectoryStructureVersion = null): void |
| 385 | + { |
| 386 | + if (in_array($symfonyDirectoryStructureVersion, [self::SYMFONY_2, self::SYMFONY_3, self::SYMFONY_4])) { |
| 387 | + $this->_symfonyDirectoryStructureVersion = $symfonyDirectoryStructureVersion; |
| 388 | + } else { |
| 389 | + $symfonyDirectoryStructureVersion = $this->_symfonyDirectoryStructureVersion; |
| 390 | + } |
| 391 | + |
| 392 | + // TODO: Be a bit more clever and for example take composer.json extra configuration into account |
| 393 | + if (self::SYMFONY_2 === $symfonyDirectoryStructureVersion) { |
370 | 394 | $this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
|
371 | 395 | $this->setDirs('app', 'app/config', 'app/cache', 'app/logs', 'src', 'app/Resources/views', 'web');
|
372 | 396 | $this->controllersToRemove(['web/app_*.php']);
|
373 | 397 | $this->sharedFiles = ['app/config/parameters.yml'];
|
374 | 398 | $this->sharedDirs = ['app/logs'];
|
375 | 399 | $this->writableDirs = ['app/cache/', 'app/logs/'];
|
376 | 400 | $this->dumpAsseticAssets = true;
|
377 |
| - } elseif (3 === $symfonyMajorVersion && 4 < $symfonyMinorVersion) { |
| 401 | + } elseif (self::SYMFONY_3 === $symfonyDirectoryStructureVersion) { |
378 | 402 | $this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
|
379 | 403 | $this->setDirs('bin', 'app/config', 'var/cache', 'var/logs', 'src', 'app/Resources/views', 'web');
|
380 | 404 | $this->controllersToRemove(['web/app_*.php']);
|
381 | 405 | $this->sharedFiles = ['app/config/parameters.yml'];
|
382 | 406 | $this->sharedDirs = ['var/logs'];
|
383 | 407 | $this->writableDirs = ['var/cache/', 'var/logs/'];
|
384 |
| - } elseif (4 === $symfonyMajorVersion || (3 === $symfonyMajorVersion && 4 >= $symfonyMinorVersion)) { |
| 408 | + } elseif (self::SYMFONY_4 === $symfonyDirectoryStructureVersion) { |
385 | 409 | $this->_symfonyEnvironmentEnvVarName = 'APP_ENV';
|
386 | 410 | $this->setDirs('bin', 'config', 'var/cache', 'var/log', 'src', 'templates', 'public');
|
387 | 411 | $this->controllersToRemove([]);
|
|
0 commit comments