improve configurations for usage in multi-environment setups (#1775)

This commit is contained in:
Kevin Papst
2020-06-11 01:26:57 +02:00
committed by GitHub
parent 57b4473bc8
commit 21d8e8bbb8
17 changed files with 66 additions and 65 deletions

View File

@@ -11,6 +11,7 @@ namespace App\Command;
use App\Constants;
use Doctrine\DBAL\Connection;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\ArrayInput;
@@ -18,6 +19,7 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Command used to do the basic installation steps for Kimai.
@@ -69,7 +71,11 @@ final class InstallCommand extends Command
$io->title('Kimai installation running ...');
$environment = getenv('APP_ENV');
/** @var Application $application */
$application = $this->getApplication();
/** @var KernelInterface $kernel */
$kernel = $application->getKernel();
$environment = $kernel->getEnvironment();
// create the database, in case it is not yet existing
try {

View File

@@ -9,12 +9,14 @@
namespace App\Command;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\StringInput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Command used to update a Kimai installation.
@@ -81,10 +83,11 @@ final class ReloadCommand extends Command
return self::ERROR_LINT_TRANSLATIONS;
}
$environment = getenv('APP_ENV');
if ($input->hasArgument('env')) {
$environment = $input->getArgument('env');
}
/** @var Application $application */
$application = $this->getApplication();
/** @var KernelInterface $kernel */
$kernel = $application->getKernel();
$environment = $kernel->getEnvironment();
// flush the cache, in case values from the database are cached
$cacheResult = $this->rebuildCaches($environment, $io, $input, $output);

View File

@@ -11,11 +11,13 @@ namespace App\Command;
use App\Constants;
use Doctrine\DBAL\Connection;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\HttpKernel\KernelInterface;
/**
* Command used to update a Kimai installation.
@@ -66,8 +68,11 @@ final class UpdateCommand extends Command
$io->title('Kimai updates running ...');
// we cannot change the environment here, as it needs to be configured in the .env file before this command is started
$environment = getenv('APP_ENV');
/** @var Application $application */
$application = $this->getApplication();
/** @var KernelInterface $kernel */
$kernel = $application->getKernel();
$environment = $kernel->getEnvironment();
// make sure database is available, Kimai running and installed
try {

View File

@@ -54,7 +54,7 @@ class AppExtension extends Extension
// safe alternatives to %kernel.project_dir%
$container->setParameter('kimai.data_dir', $config['data_dir']);
$container->setParameter('kimai.plugin_dir', $config['plugin_dir']);
$container->setParameter('kimai.plugin_dir', $container->getParameter('kernel.project_dir') . '/var/plugins');
$this->setLanguageFormats($config['languages'], $container);
unset($config['languages']);

View File

@@ -46,13 +46,7 @@ class Configuration implements ConfigurationInterface
->end()
->end()
->scalarNode('plugin_dir')
->isRequired()
->validate()
->ifTrue(function ($value) {
return !file_exists($value);
})
->thenInvalid('Plugin directory does not exist')
->end()
->setDeprecated('Changing the plugin directory via "kimai.plugin_dir" is not supported since 1.9')
->end()
->append($this->getUserNode())
->append($this->getTimesheetNode())

View File

@@ -98,6 +98,23 @@ class Kernel extends BaseKernel
}
}
if ($this->environment === 'test' && getenv('TEST_WITH_BUNDLES') === false) {
return;
}
// we can either define all kimai bundles hardcoded ...
if (is_file($this->getProjectDir() . '/config/bundles-local.php')) {
$contents = require $this->getProjectDir() . '/config/bundles-local.php';
foreach ($contents as $class => $envs) {
if (isset($envs['all']) || isset($envs[$this->environment])) {
yield new $class();
}
}
return;
}
// ... or we load them dynamically from the plugins directory
foreach ($this->getBundleDirectories() as $bundleDir) {
$bundleName = $bundleDir->getRelativePathname();
$pluginClass = 'KimaiPlugin\\' . $bundleName . '\\' . $bundleName;
@@ -112,10 +129,6 @@ class Kernel extends BaseKernel
return [];
}
if ($this->environment === 'test' && getenv('TEST_WITH_BUNDLES') === false) {
return [];
}
$directories = [];
$finder = new Finder();
$finder->ignoreUnreadableDirs()->directories()->name('*Bundle');
@@ -207,9 +220,10 @@ class Kernel extends BaseKernel
// load application routes
$routes->import($confDir . '/routes' . self::CONFIG_EXTS, '/', 'glob');
/** @var SplFileInfo $bundleDir */
foreach ($this->getBundleDirectories() as $bundleDir) {
$routes->import($bundleDir->getRealPath() . '/Resources/config/routes' . self::CONFIG_EXTS, '/', 'glob');
foreach ($this->bundles as $bundle) {
if (strpos(\get_class($bundle), 'KimaiPlugin\\') !== false) {
$routes->import($bundle->getPath() . '/Resources/config/routes' . self::CONFIG_EXTS, '/', 'glob');
}
}
}