Skip to content

Commit e84cdc2

Browse files
committed
bug #19 Fixed default config path guessing (HeahDude, javiereguiluz)
This PR was merged into the 1.0.x-dev branch. Discussion ---------- Fixed default config path guessing Closes #16. What do you think of doing it this way? Commits ------- bec7bbf Minor refactor 20226ab Fixed default config path guessing
2 parents 0cd7703 + bec7bbf commit e84cdc2

File tree

4 files changed

+38
-58
lines changed

4 files changed

+38
-58
lines changed

src/Command/DeployCommand.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace EasyCorp\Bundle\EasyDeployBundle\Command;
1313

1414
use EasyCorp\Bundle\EasyDeployBundle\Context;
15-
use EasyCorp\Bundle\EasyDeployBundle\Exception\SymfonyVersionException;
15+
use EasyCorp\Bundle\EasyDeployBundle\Helper\SymfonyConfigPathGuesser;
1616
use Symfony\Component\Console\Command\Command;
1717
use Symfony\Component\Console\Input\InputArgument;
1818
use Symfony\Component\Console\Input\InputInterface;
@@ -21,7 +21,6 @@
2121
use Symfony\Component\Console\Question\ConfirmationQuestion;
2222
use Symfony\Component\Filesystem\Filesystem;
2323
use Symfony\Component\HttpKernel\Config\FileLocator;
24-
use Symfony\Component\HttpKernel\Kernel;
2524

2625
class DeployCommand extends Command
2726
{
@@ -62,7 +61,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
6261
return $this->configFilePath = $customConfigPath;
6362
}
6463

65-
$defaultConfigPath = $this->getDefaultConfigPath($input->getArgument('stage'));
64+
$defaultConfigPath = SymfonyConfigPathGuesser::guess($this->projectDir, $input->getArgument('stage'));
6665
if (is_readable($defaultConfigPath)) {
6766
return $this->configFilePath = $defaultConfigPath;
6867
}
@@ -80,22 +79,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
8079
$deployer->doDeploy();
8180
}
8281

83-
private function getDefaultConfigPath(string $stageName) : string
84-
{
85-
$symfonyVersion = Kernel::MAJOR_VERSION;
86-
$defaultConfigPaths = [
87-
2 => sprintf('%s/app/config/deploy_%s.php', $this->projectDir, $stageName),
88-
3 => sprintf('%s/app/config/deploy_%s.php', $this->projectDir, $stageName),
89-
4 => sprintf('%s/etc/%s/deploy.php', $this->projectDir, $stageName),
90-
];
91-
92-
if (!isset($defaultConfigPaths[$symfonyVersion])) {
93-
throw new SymfonyVersionException($symfonyVersion);
94-
}
95-
96-
return $defaultConfigPaths[$symfonyVersion];
97-
}
98-
9982
private function createDefaultConfigFile(InputInterface $input, OutputInterface $output, string $defaultConfigPath, string $stageName) : void
10083
{
10184
$helper = $this->getHelper('question');

src/Command/RollbackCommand.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
namespace EasyCorp\Bundle\EasyDeployBundle\Command;
1313

1414
use EasyCorp\Bundle\EasyDeployBundle\Context;
15-
use EasyCorp\Bundle\EasyDeployBundle\Exception\SymfonyVersionException;
15+
use EasyCorp\Bundle\EasyDeployBundle\Helper\SymfonyConfigPathGuesser;
1616
use Symfony\Component\Console\Command\Command;
1717
use Symfony\Component\Console\Input\InputArgument;
1818
use Symfony\Component\Console\Input\InputInterface;
1919
use Symfony\Component\Console\Input\InputOption;
2020
use Symfony\Component\Console\Output\OutputInterface;
21-
use Symfony\Component\HttpKernel\Kernel;
2221

2322
class RollbackCommand extends Command
2423
{
@@ -57,7 +56,7 @@ protected function initialize(InputInterface $input, OutputInterface $output)
5756
return $this->configFilePath = $customConfigPath;
5857
}
5958

60-
$defaultConfigPath = $this->getDefaultConfigPath($input->getArgument('stage'));
59+
$defaultConfigPath = SymfonyConfigPathGuesser::guess($this->projectDir, $input->getArgument('stage'));
6160
if (is_readable($defaultConfigPath)) {
6261
return $this->configFilePath = $defaultConfigPath;
6362
}
@@ -74,20 +73,4 @@ protected function execute(InputInterface $input, OutputInterface $output)
7473
$deployer->initialize($context);
7574
$deployer->doRollback();
7675
}
77-
78-
private function getDefaultConfigPath(string $stageName) : string
79-
{
80-
$symfonyVersion = Kernel::MAJOR_VERSION;
81-
$defaultConfigPaths = [
82-
2 => sprintf('%s/app/config/deploy_%s.php', $this->projectDir, $stageName),
83-
3 => sprintf('%s/app/config/deploy_%s.php', $this->projectDir, $stageName),
84-
4 => sprintf('%s/etc/%s/deploy.php', $this->projectDir, $stageName),
85-
];
86-
87-
if (!isset($defaultConfigPaths[$symfonyVersion])) {
88-
throw new SymfonyVersionException($symfonyVersion);
89-
}
90-
91-
return $defaultConfigPaths[$symfonyVersion];
92-
}
9376
}

src/Exception/SymfonyVersionException.php

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the EasyDeploy project.
5+
*
6+
* (c) Javier Eguiluz <javier.eguiluz@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace EasyCorp\Bundle\EasyDeployBundle\Helper;
13+
14+
/**
15+
* @author Jules Pietri <jules@heahprod.com>
16+
*/
17+
class SymfonyConfigPathGuesser
18+
{
19+
private const LEGACY_CONFIG_DIR = '%s/app/config';
20+
private const CONFIG_DIR = '%s/etc';
21+
22+
public static function guess(string $projectDir, string $stage): string
23+
{
24+
if (is_dir($configDir = sprintf(self::CONFIG_DIR, $projectDir))) {
25+
return sprintf('%s/%s/deploy.php', $configDir, $stage);
26+
}
27+
28+
if (is_dir($configDir = sprintf(self::LEGACY_CONFIG_DIR, $projectDir))) {
29+
return sprintf('%s/deploy_%s.php', $configDir, $stage);
30+
}
31+
32+
throw new \RuntimeException(sprintf('None of the usual Symfony config dirs exist in the application. Create one of these dirs before continuing: "%s" or "%s".', self::CONFIG_DIR, self::LEGACY_CONFIG_DIR));
33+
}
34+
}

0 commit comments

Comments
 (0)