Skip to content

Commit cbb8b22

Browse files
committed
add config:preview command
1 parent d78c1b0 commit cbb8b22

File tree

6 files changed

+572
-17
lines changed

6 files changed

+572
-17
lines changed

psalm-baseline.xml

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="6.10.1@f9fd6bc117e9ce1e854c2ed6777e7135aaa4966b">
2+
<files psalm-version="6.13.1@1e3b7f0a8ab32b23197b91107adc0a7ed8a05b51">
33
<file src="src/Propel/Common/Config/ConfigurationManager.php">
44
<UnsupportedPropertyReferenceUsage>
55
<code><![CDATA[$configSection = &$this->config[$section]]]></code>
@@ -105,14 +105,11 @@
105105
</file>
106106
<file src="src/Propel/Generator/Manager/AbstractManager.php">
107107
<UndefinedClass>
108-
<code><![CDATA[$xsl]]></code>
109-
<code><![CDATA[$xsl]]></code>
110108
<code><![CDATA[XSLTProcessor]]></code>
111109
</UndefinedClass>
112110
<UndefinedMethod>
113111
<code><![CDATA[getAttribute]]></code>
114112
<code><![CDATA[getAttribute]]></code>
115-
<code><![CDATA[getLocation]]></code>
116113
</UndefinedMethod>
117114
</file>
118115
<file src="src/Propel/Generator/Manager/DataDictionaryExportManager.php">
@@ -123,6 +120,11 @@
123120
<code><![CDATA[preg_replace('/\W/', '-', $name)]]></code>
124121
</NullableReturnStatement>
125122
</file>
123+
<file src="src/Propel/Generator/Manager/PrintPropelDirectoriesManager.php">
124+
<UnsupportedPropertyReferenceUsage>
125+
<code><![CDATA[$location = &$this->directoryStructure]]></code>
126+
</UnsupportedPropertyReferenceUsage>
127+
</file>
126128
<file src="src/Propel/Generator/Model/Index.php">
127129
<InvalidNullableReturnType>
128130
<code><![CDATA[string]]></code>
@@ -237,12 +239,6 @@
237239
<code><![CDATA[save]]></code>
238240
</UndefinedInterfaceMethod>
239241
</file>
240-
<file src="src/Propel/Runtime/Collection/ObjectCollection.php">
241-
<UndefinedInterfaceMethod>
242-
<code><![CDATA[delete]]></code>
243-
<code><![CDATA[save]]></code>
244-
</UndefinedInterfaceMethod>
245-
</file>
246242
<file src="src/Propel/Runtime/Connection/StatementWrapper.php">
247243
<InvalidNullableReturnType>
248244
<code><![CDATA[string]]></code>

src/Propel/Common/Config/PropelConfiguration.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,14 @@ protected function addPathsSection(ArrayNodeDefinition $node): void
7676
->arrayNode('paths')
7777
->addDefaultsIfNotSet()
7878
->children()
79-
->scalarNode('projectDir')->defaultValue(getcwd())->end()
80-
->scalarNode('schemaDir')->defaultValue(getcwd())->end()
81-
->scalarNode('outputDir')->defaultValue(getcwd())->end()
82-
->scalarNode('phpDir')->defaultValue(getcwd() . '/generated-classes')->end()
83-
->scalarNode('phpConfDir')->defaultValue(getcwd() . '/generated-conf')->end()
79+
->scalarNode('projectDir')->defaultValue('.')->end()
80+
->scalarNode('schemaDir')->defaultValue('.')->end()
81+
->scalarNode('outputDir')->defaultValue('.')->end()
82+
->scalarNode('phpDir')->defaultValue('./generated-classes')->end()
83+
->scalarNode('phpConfDir')->defaultValue('./generated-conf')->end()
8484
->scalarNode('loaderScriptDir')->end()
85-
->scalarNode('sqlDir')->defaultValue(getcwd() . '/generated-sql')->end()
86-
->scalarNode('migrationDir')->defaultValue(getcwd() . '/generated-migrations')->end()
85+
->scalarNode('sqlDir')->defaultValue('./generated-sql')->end()
86+
->scalarNode('migrationDir')->defaultValue('./generated-migrations')->end()
8787
->scalarNode('composerDir')->defaultNull()->end()
8888
->end()
8989
->end()
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
/**
4+
* MIT License. This file is part of the Propel package.
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
namespace Propel\Generator\Command;
10+
11+
use Propel\Generator\Manager\PrintPropelDirectoriesManager;
12+
use Symfony\Component\Console\Input\InputInterface;
13+
use Symfony\Component\Console\Input\InputOption;
14+
use Symfony\Component\Console\Output\OutputInterface;
15+
16+
class PrintPropelDirectoriesCommand extends AbstractCommand
17+
{
18+
/**
19+
* @inheritDoc
20+
*/
21+
#[\Override]
22+
protected function configure()
23+
{
24+
parent::configure();
25+
26+
$this
27+
->addOption('schema-dir', null, InputOption::VALUE_REQUIRED, 'The directory where the schema files are placed')
28+
->addOption('connection', null, InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Connection to use. Example: \'bookstore=mysql:host=127.0.0.1;dbname=test;user=root;password=foobar\' where "bookstore" is your propel database name (used in your schema.xml)', [])
29+
->setName('config:preview')
30+
->setDescription('Output directory structure of files and directories known to Perpl with current configuration, including auto-generated files.');
31+
}
32+
33+
/**
34+
* @inheritDoc
35+
*/
36+
#[\Override]
37+
protected function execute(InputInterface $input, OutputInterface $output): int
38+
{
39+
$config = $this->buildGeneratorConfig([], $input, [
40+
'schema-dir' => 'paths.schemaDir',
41+
]);
42+
43+
$manager = new PrintPropelDirectoriesManager();
44+
$manager->setGeneratorConfig($config);
45+
$schemas = $this->getSchemasFromConfig($config);
46+
$manager->setSchemas($schemas);
47+
$manager->setLoggerClosure(fn ($data) => $output->write($data));
48+
$manager->build();
49+
50+
return static::CODE_SUCCESS;
51+
}
52+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<?php
2+
3+
/**
4+
* MIT License. This file is part of the Propel package.
5+
* For the full copyright and license information, please view the LICENSE
6+
* file that was distributed with this source code.
7+
*/
8+
9+
namespace Propel\Generator\Manager;
10+
11+
use Propel\Generator\Builder\Om\AbstractOMBuilder;
12+
use Propel\Generator\Builder\Om\TableMapLoaderScriptBuilder;
13+
use SplFileInfo;
14+
use Symfony\Component\Filesystem\Path;
15+
16+
/**
17+
* Build list of files that model:build would create
18+
*/
19+
class ModelDryRunManager extends ModelManager
20+
{
21+
protected array $filePathCollector = [];
22+
23+
/**
24+
* @return array<array{path: string, status: string}>
25+
*/
26+
public function getCollectedFilePaths(): array
27+
{
28+
return $this->filePathCollector;
29+
}
30+
31+
/**
32+
* @return void
33+
*/
34+
#[\Override()]
35+
public function build(): void
36+
{
37+
parent::build();
38+
}
39+
40+
/**
41+
* @param string $configProp
42+
*
43+
* @return bool
44+
*/
45+
protected function isFromRelativeConfig(string $configProp): bool
46+
{
47+
return Path::isRelative($this->getGeneratorConfig()->getConfigPropertyString($configProp, true));
48+
}
49+
50+
/**
51+
* @param \Propel\Generator\Builder\Om\AbstractOMBuilder $builder
52+
* @param bool $overwrite
53+
*
54+
* @return int
55+
*/
56+
#[\Override]
57+
protected function doBuild(AbstractOMBuilder $builder, bool $overwrite = true): int
58+
{
59+
$path = $builder->getClassFilePath();
60+
$file = new SplFileInfo($this->getWorkingDirectory() . DIRECTORY_SEPARATOR . $path);
61+
$fromRelativeConfig = $this->isFromRelativeConfig('paths.phpDir');
62+
if (!$file->isFile()) {
63+
$this->filePathCollector[] = ['path' => $file->getPathname(), 'status' => '(new)'];
64+
} else {
65+
$overrideBehavior = $overwrite ? 'override if changed' : 'no override';
66+
$this->filePathCollector[] = ['path' => $file->getRealPath(), 'status' => "(exists, $overrideBehavior)"];
67+
}
68+
69+
return 1;
70+
}
71+
72+
/**
73+
* Create script to import all table map files into database map.
74+
*
75+
* @return int Number of changed files
76+
*/
77+
#[\Override]
78+
protected function createTableMapLoaderScript(): int
79+
{
80+
$builder = new TableMapLoaderScriptBuilder($this->getGeneratorConfig());
81+
$file = $builder->getFile();
82+
$filePath = $file->getPathname();
83+
if ($this->isFromRelativeConfig('paths.phpConfDir')) {
84+
$filePath = Path::makeAbsolute($filePath, getcwd() ?: '.');
85+
}
86+
87+
$status = $file->isFile() ? 'recreate' : 'new';
88+
$this->filePathCollector[] = ['path' => $filePath, 'status' => "($status)"];
89+
90+
return 1;
91+
}
92+
}

0 commit comments

Comments
 (0)