Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Symfony 3.4 default directory issue #5

Merged
merged 1 commit into from
Nov 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 33 additions & 8 deletions src/Configuration/DefaultConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
*/
final class DefaultConfiguration extends AbstractConfiguration
{
const SYMFONY_2 = 2;
const SYMFONY_3 = 3;
const SYMFONY_4 = 4;
const SYMFONY_5 = 5;

// variables starting with an underscore are for internal use only
private $_symfonyEnvironmentEnvVarName; // SYMFONY_ENV or APP_ENV

Expand Down Expand Up @@ -65,7 +70,7 @@ public function __construct(string $localProjectDir)
{
parent::__construct();
$this->localProjectDir = $localProjectDir;
$this->setDefaultConfiguration(Kernel::MAJOR_VERSION, Kernel::MINOR_VERSION);
$this->setDefaultConfiguration(Kernel::MAJOR_VERSION);
}

// this proxy method is needed because the autocompletion breaks
Expand Down Expand Up @@ -368,30 +373,50 @@ 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];
}

private function setDefaultConfiguration(int $symfonyMajorVersion, $symfonyMinorVersion): void
private function setDefaultConfiguration(int $symfonyMajorVersion): self
{
if (2 === $symfonyMajorVersion) {
$this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
if(self::SYMFONY_2 > $symfonyMajorVersion || self::SYMFONY_5 < $symfonyMajorVersion)
{
throw new \InvalidArgumentException("%d is not a supported Symfony version.", $symfonyMajorVersion);
}

$this->setEnvironmentVarName($symfonyMajorVersion);

if (self::SYMFONY_2 === $symfonyMajorVersion) {
$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 (3 === $symfonyMajorVersion && 4 < $symfonyMinorVersion) {
$this->_symfonyEnvironmentEnvVarName = 'SYMFONY_ENV';
} elseif (self::SYMFONY_3 === $symfonyMajorVersion) {
$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 (4 <= $symfonyMajorVersion || (3 === $symfonyMajorVersion && 4 >= $symfonyMinorVersion)) {
$this->_symfonyEnvironmentEnvVarName = 'APP_ENV';
} elseif (self::SYMFONY_4 <= $symfonyMajorVersion) { // support Symfony 4 or above
$this->setDirs('bin', 'config', 'var/cache', 'var/log', 'src', 'templates', 'public');
$this->controllersToRemove([]);
$this->sharedDirs = ['var/log'];
$this->writableDirs = ['var/cache/', 'var/log/'];
}

return $this;
}

/**
* 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
Expand Down