Skip to content

Commit

Permalink
Change root_dir to project_dir
Browse files Browse the repository at this point in the history
  • Loading branch information
mwaterboehr committed Sep 12, 2023
1 parent 3e1d18d commit 00d8a6c
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 22 deletions.
21 changes: 13 additions & 8 deletions Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'))
Expand All @@ -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');
Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion Command/DatabaseDropCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion Command/FixturesDumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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("<info>The $path folder does not exists.</info>");
Expand Down
2 changes: 1 addition & 1 deletion Command/FixturesLoadCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
6 changes: 3 additions & 3 deletions Command/FormGenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class FormGenerateCommand extends AbstractCommand
{
const DEFAULT_FORM_TYPE_DIRECTORY = '/Form/Type';

use BundleTrait;

/**
Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Command/ModelBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
2 changes: 1 addition & 1 deletion Command/TableDropCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/PropelExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions Resources/config/propel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@
</service>

<service id="propel.dumper.yaml" class="%propel.dumper.yaml.class%">
<argument>%kernel.root_dir%</argument>
<argument>%kernel.project_dir%</argument>
<argument>%propel.configuration%</argument>
</service>

<service id="propel.loader.yaml" class="%propel.loader.yaml.class%" public="true">
<argument>%kernel.root_dir%</argument>
<argument>%kernel.project_dir%</argument>
<argument>%propel.configuration%</argument>
<argument type="service" id="faker.generator" on-invalid="null" />
</service>

<service id="propel.loader.xml" class="%propel.loader.xml.class%">
<argument>%kernel.root_dir%</argument>
<argument>%kernel.project_dir%</argument>
<argument>%propel.configuration%</argument>
</service>

Expand Down
4 changes: 2 additions & 2 deletions Tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 00d8a6c

Please sign in to comment.