diff --git a/Command/AbstractCommand.php b/Command/AbstractCommand.php
index 2bc4edb1..b9d8a308 100644
--- a/Command/AbstractCommand.php
+++ b/Command/AbstractCommand.php
@@ -10,6 +10,7 @@
namespace Propel\Bundle\PropelBundle\Command;
+use Symfony\Bundle\FrameworkBundle\Console\Application;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
@@ -49,11 +50,9 @@ public function getContainer(): ContainerInterface
*/
protected function initialize(InputInterface $input, OutputInterface $output)
{
- $kernel = $this->getApplication()->getKernel();
-
$this->input = $input;
$this->output = $output;
- $this->cacheDir = $kernel->getCacheDir().'/propel';
+ $this->cacheDir = $this->getKernel()->getCacheDir().'/propel';
if ($input->hasArgument('bundle')
&& !empty($input->getArgument('bundle'))
@@ -71,13 +70,11 @@ protected function initialize(InputInterface $input, OutputInterface $output)
*/
protected function setupBuildTimeFiles()
{
- $kernel = $this->getApplication()->getKernel();
-
$fs = new Filesystem();
$fs->mkdir($this->cacheDir);
// collect all schemas
- $this->copySchemas($kernel, $this->cacheDir);
+ $this->copySchemas($this->getKernel(), $this->cacheDir);
// propel.json
$this->createPropelConfigurationFile($this->cacheDir.'/propel.json');
@@ -95,7 +92,7 @@ protected function copySchemas(KernelInterface $kernel, $cacheDir)
$finalSchemas = $this->getFinalSchemas($kernel, $this->bundle);
foreach ($finalSchemas as $schema) {
/** @var null|Bundle $bundle */
- list($bundle, $finalSchema) = $schema;
+ [$bundle, $finalSchema] = $schema;
if ($bundle) {
$file = $cacheDir.DIRECTORY_SEPARATOR.'bundle-'.$bundle->getName().'-'.$finalSchema->getBaseName();
@@ -348,7 +345,7 @@ protected function getPackageFromBundle(Bundle $bundle, $namespace)
$namespaceDiff = substr($namespace, strlen($baseNamespace) + 1);
$bundlePath = realpath($bundle->getPath()) . '/' . str_replace('\\', '/', $namespaceDiff);
- $appPath = realpath($this->getApplication()->getKernel()->getRootDir() . '/..');
+ $appPath = realpath($this->getKernel()->getProjectDir() . '/..');
$path = static::getRelativePath($bundlePath, $appPath);
@@ -451,4 +448,12 @@ protected function getPlatform()
$config = $this->getContainer()->getParameter('propel.configuration');
return $config['generator']['platformClass'];
}
+
+ protected function getKernel(): KernelInterface
+ {
+ /** @var Application $application */
+ $application = $this->getApplication();
+
+ return $application->getKernel();
+ }
}
diff --git a/Command/DatabaseDropCommand.php b/Command/DatabaseDropCommand.php
index 5dcc0c1c..553fcbde 100644
--- a/Command/DatabaseDropCommand.php
+++ b/Command/DatabaseDropCommand.php
@@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
return;
}
- if ('prod' === $this->getApplication()->getKernel()->getEnvironment()) {
+ if ('prod' === $this->getKernel()->getEnvironment()) {
$this->writeSection($output, 'WARNING: you are about to drop a database in production !', 'bg=red;fg=white');
if (false === $this->askConfirmation($input, $output, 'Are you sure ? (y/n) ', false)) {
diff --git a/Command/FixturesDumpCommand.php b/Command/FixturesDumpCommand.php
index e23330f8..89970fbf 100644
--- a/Command/FixturesDumpCommand.php
+++ b/Command/FixturesDumpCommand.php
@@ -58,7 +58,7 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$fixtureDir = $input->getOption('dir') ?: $this->defaultFixturesDir;
- $path = realpath($this->getApplication()->getKernel()->getRootDir() . '/../') . '/' . $fixtureDir;
+ $path = realpath($this->getKernel()->getProjectDir() . '/../') . '/' . $fixtureDir;
if (!file_exists($path)) {
$output->writeln("The $path folder does not exists.");
diff --git a/Command/FixturesLoadCommand.php b/Command/FixturesLoadCommand.php
index c82927a1..e9ae4416 100644
--- a/Command/FixturesLoadCommand.php
+++ b/Command/FixturesLoadCommand.php
@@ -119,7 +119,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (null !== $this->bundle) {
$this->absoluteFixturesPath = $this->getFixturesPath($this->bundle);
} else {
- $this->absoluteFixturesPath = realpath($this->getApplication()->getKernel()->getRootDir() . '/../' . $input->getOption('dir'));
+ $this->absoluteFixturesPath = realpath($this->getKernel()->getProjectDir() . '/../' . $input->getOption('dir'));
}
if (!$this->absoluteFixturesPath && !file_exists($this->absoluteFixturesPath)) {
diff --git a/Command/FormGenerateCommand.php b/Command/FormGenerateCommand.php
index 7e57c790..18c97005 100644
--- a/Command/FormGenerateCommand.php
+++ b/Command/FormGenerateCommand.php
@@ -29,7 +29,7 @@
class FormGenerateCommand extends AbstractCommand
{
const DEFAULT_FORM_TYPE_DIRECTORY = '/Form/Type';
-
+
use BundleTrait;
/**
@@ -61,7 +61,7 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
- $kernel = $this->getApplication()->getKernel();
+ $kernel = $this->getKernel();
$models = $input->getArgument('models');
$force = $input->getOption('force');
@@ -155,7 +155,7 @@ protected function writeFormType(BundleInterface $bundle, Table $table, \SplFile
*/
protected function getRelativeFileName(\SplFileInfo $file)
{
- return substr(str_replace(realpath($this->getContainer()->getParameter('kernel.root_dir') . '/../'), '', $file), 1);
+ return substr(str_replace(realpath($this->getContainer()->getParameter('kernel.project_dir') . '/../'), '', $file), 1);
}
/**
diff --git a/Command/ModelBuildCommand.php b/Command/ModelBuildCommand.php
index 5d7271f9..592f0b25 100644
--- a/Command/ModelBuildCommand.php
+++ b/Command/ModelBuildCommand.php
@@ -52,7 +52,7 @@ protected function createSubCommandInstance()
*/
protected function getSubCommandArguments(InputInterface $input)
{
- $outputDirDefault = $this->getApplication()->getKernel()->getRootDir().'/../';
+ $outputDirDefault = $this->getApplication()->getKernel()->getProjectDir().'/../';
$outputDir = $this->input->getOption('output-dir') ?: $outputDirDefault;
$result = [
diff --git a/Command/TableDropCommand.php b/Command/TableDropCommand.php
index 0cc51834..541207cb 100644
--- a/Command/TableDropCommand.php
+++ b/Command/TableDropCommand.php
@@ -59,7 +59,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$nbTable = count($tablesToDelete);
$tablePlural = (($nbTable > 1 || $nbTable == 0) ? 's' : '' );
- if ('prod' === $this->getApplication()->getKernel()->getEnvironment()) {
+ if ('prod' === $this->getKernel()->getEnvironment()) {
$count = $nbTable ?: 'all';
$this->writeSection(
diff --git a/DependencyInjection/PropelExtension.php b/DependencyInjection/PropelExtension.php
index 68262340..8f4bdc16 100644
--- a/DependencyInjection/PropelExtension.php
+++ b/DependencyInjection/PropelExtension.php
@@ -62,7 +62,7 @@ public function load(array $configs, ContainerBuilder $container)
public function getConfiguration(array $config, ContainerBuilder $container)
{
- return new Configuration($container->getParameter('kernel.debug'), $container->getParameter('kernel.root_dir'));
+ return new Configuration($container->getParameter('kernel.debug'), $container->getParameter('kernel.project_dir'));
}
/**
diff --git a/Resources/config/propel.xml b/Resources/config/propel.xml
index f59e09f0..45cb3f52 100644
--- a/Resources/config/propel.xml
+++ b/Resources/config/propel.xml
@@ -48,18 +48,18 @@
- %kernel.root_dir%
+ %kernel.project_dir%
%propel.configuration%
- %kernel.root_dir%
+ %kernel.project_dir%
%propel.configuration%
- %kernel.root_dir%
+ %kernel.project_dir%
%propel.configuration%
diff --git a/Tests/TestCase.php b/Tests/TestCase.php
index f3bf8ea0..e3611296 100644
--- a/Tests/TestCase.php
+++ b/Tests/TestCase.php
@@ -23,8 +23,8 @@ class TestCase extends BaseTestCase
public function getContainer()
{
$container = new ContainerBuilder(new ParameterBag(array(
- 'kernel.debug' => false,
- 'kernel.root_dir' => __DIR__ . '/../',
+ 'kernel.debug' => false,
+ 'kernel.project_dir' => __DIR__ . '/../',
)));
$container->setParameter('propel.configuration', array());