Skip to content

Commit c39984d

Browse files
authored
Merge pull request #93 from perplorm/console_fixes
Console fixes
2 parents 3d7d3fd + 97b63f9 commit c39984d

File tree

60 files changed

+919
-670
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+919
-670
lines changed

bin/perpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env php
2+
<?php
3+
4+
require(__DIR__ . '/perpl.php');

bin/perpl.bat

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@echo off
2+
3+
if "%PHPBIN%" == "" set PHPBIN=php
4+
if not exist "%PHPBIN%" if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_PATH
5+
GOTO RUN
6+
:USE_PEAR_PATH
7+
set PHPBIN=%PHP_PEAR_PHP_BIN%
8+
:RUN
9+
"%PHPBIN%" "bin\perpl" %*

bin/perpl.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
if (!class_exists(\Symfony\Component\Console\Application::class)) {
4+
$autoloadFileCandidates = [
5+
__DIR__ . '/../../../autoload.php',
6+
__DIR__ . '/../autoload.php',
7+
__DIR__ . '/../autoload.php.dist',
8+
];
9+
foreach ($autoloadFileCandidates as $file) {
10+
if (file_exists($file)) {
11+
require_once $file;
12+
13+
break;
14+
}
15+
}
16+
}
17+
18+
use Propel\Generator\Application;
19+
use Propel\Runtime\Propel;
20+
use Symfony\Component\Console\Command\Command;
21+
use Symfony\Component\Finder\Finder;
22+
23+
$finder = new Finder();
24+
$finder->files()->name('*.php')->in(__DIR__ . '/../src/Propel/Generator/Command')->depth(0);
25+
26+
$app = new Application('Perpl', Propel::VERSION);
27+
28+
$ns = '\\Propel\\Generator\\Command\\';
29+
30+
foreach ($finder as $file) {
31+
$r = new \ReflectionClass($ns . $file->getBasename('.php'));
32+
if ($r->isSubclassOf(Command::class) && !$r->isAbstract()) {
33+
$app->addCommands([$r->newInstance()]); // Using addCommands for BC with Symfony <8.0
34+
}
35+
}
36+
37+
$app->run();

bin/propel.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ GOTO RUN
66
:USE_PEAR_PATH
77
set PHPBIN=%PHP_PEAR_PHP_BIN%
88
:RUN
9-
"%PHPBIN%" "bin\propel" %*
9+
"%PHPBIN%" "bin\perpl" %*

bin/propel.php

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,3 @@
11
<?php
22

3-
if (!class_exists(\Symfony\Component\Console\Application::class)) {
4-
$autoloadFileCandidates = [
5-
__DIR__ . '/../../../autoload.php',
6-
__DIR__ . '/../autoload.php',
7-
__DIR__ . '/../autoload.php.dist',
8-
];
9-
foreach ($autoloadFileCandidates as $file) {
10-
if (file_exists($file)) {
11-
require_once $file;
12-
13-
break;
14-
}
15-
}
16-
}
17-
18-
use Propel\Generator\Application;
19-
use Propel\Runtime\Propel;
20-
use Symfony\Component\Console\Command\Command;
21-
use Symfony\Component\Finder\Finder;
22-
23-
$finder = new Finder();
24-
$finder->files()->name('*.php')->in(__DIR__ . '/../src/Propel/Generator/Command')->depth(0);
25-
26-
$app = new Application('Propel', Propel::VERSION);
27-
28-
$ns = '\\Propel\\Generator\\Command\\';
29-
30-
foreach ($finder as $file) {
31-
$r = new \ReflectionClass($ns . $file->getBasename('.php'));
32-
if ($r->isSubclassOf(Command::class) && !$r->isAbstract()) {
33-
$app->addCommands([$r->newInstance()]); // Using addCommands for BC with Symfony <8.0
34-
}
35-
}
36-
37-
$app->run();
3+
require(__DIR__ . '/perpl.php');

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
}
6060
},
6161
"bin": [
62+
"bin/perpl",
6263
"bin/propel"
6364
],
6465
"scripts": {

src/Propel/Common/Config/ConfigurationManager.php

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
*/
2626
class ConfigurationManager
2727
{
28-
/**
29-
* @var string
30-
*/
31-
public const CONFIG_FILE_NAME = 'propel';
32-
3328
/**
3429
* @var int
3530
*/
@@ -72,6 +67,8 @@ public function __construct(?string $path = null, ?array $extraConf = [])
7267
}
7368

7469
/**
70+
* @deprecated Use aptly named {@see ConfigurationManager::getConfig()}
71+
*
7572
* Return the whole configuration array
7673
*
7774
* @return array
@@ -82,6 +79,18 @@ public function get(): array
8279
}
8380

8481
/**
82+
* Return the whole configuration array
83+
*
84+
* @return array
85+
*/
86+
public function getConfig(): array
87+
{
88+
return $this->config;
89+
}
90+
91+
/**
92+
* @deprecated Access config props (including full sections) through {@see static::getConfigProperty()}
93+
*
8594
* Return a specific section of the configuration array.
8695
* It ca be useful to get, in example, only 'generator' values.
8796
*
@@ -106,28 +115,77 @@ public function getSection(string $section): ?array
106115
* is expressed by:
107116
* <code>'database.adapter.mysql.tableType</code>
108117
*
109-
* @param string $name The name of property, expressed as a dot separated level hierarchy
118+
* @psalm-return ($isRequired ? array|int|bool|string : array|scalar|null)
119+
*
120+
* @param string $path The name of property, expressed as a dot separated level hierarchy
121+
* @param bool $isRequired
110122
*
123+
* @throws \Propel\Common\Config\Exception\InvalidConfigurationException
111124
* @throws \Propel\Common\Config\Exception\InvalidArgumentException
112125
*
113-
* @return mixed The configuration property
126+
* @return array|string|int|bool|null The configuration property
114127
*/
115-
public function getConfigProperty(string $name)
128+
public function getConfigProperty(string $path, bool $isRequired = false): array|int|bool|string|null
116129
{
117-
if ($name === '') {
130+
if ($path === '') {
118131
throw new InvalidArgumentException('Invalid empty configuration property name.');
119132
}
120133

121-
$keys = explode('.', $name);
122-
$output = $this->get();
134+
$keys = explode('.', $path);
135+
$section = $this->getConfig();
123136
foreach ($keys as $key) {
124-
if (!array_key_exists($key, $output)) {
125-
return null;
137+
if (array_key_exists($key, $section)) {
138+
$section = $section[$key];
139+
140+
continue;
126141
}
127-
$output = $output[$key];
142+
143+
if ($isRequired) {
144+
throw new InvalidConfigurationException("Cannot resolve config property '$path': No value at '$key'");
145+
}
146+
147+
return null;
128148
}
129149

130-
return $output;
150+
if ($isRequired && ($section === null || $section === '')) {
151+
throw new InvalidConfigurationException("Required config property '$path' cannot be empty, but is: " . var_export($section, true));
152+
}
153+
154+
return $section;
155+
}
156+
157+
/**
158+
* Type-safe access of {@see static::getConfigProperty()}.
159+
*
160+
* @psalm-return ($isRequired ? string : string|null)
161+
*
162+
* @param string $path The name of property, expressed as a dot separated level hierarchy
163+
* @param bool $isRequired
164+
*
165+
* @throws \Propel\Common\Config\Exception\InvalidConfigurationException
166+
*
167+
* @return string|null The configuration property
168+
*/
169+
public function getConfigPropertyString(string $path, bool $isRequired = false): string|null
170+
{
171+
$val = $this->getConfigProperty($path, $isRequired);
172+
if ($val === null || is_string($val)) {
173+
return $val;
174+
}
175+
176+
throw new InvalidConfigurationException("Configuration item `$path` is expected to contain a string, but is " . var_export($val, true));
177+
}
178+
179+
/**
180+
* Return a specific configuration property.
181+
*
182+
* @param string $path The name of property, expressed as a dot separated level hierarchy
183+
*
184+
* @return array|string|int|bool The configuration property
185+
*/
186+
public function getConfigPropertyRequired(string $path): array|int|bool|string
187+
{
188+
return $this->getConfigProperty($path, true) ?? '';
131189
}
132190

133191
/**
@@ -215,7 +273,7 @@ protected function process(array $extraConf = []): void
215273
try {
216274
$this->config = $processor->processConfiguration($configuration, $this->config);
217275
} catch (SymfonyInvalidConfigurationException $e) {
218-
throw new InvalidConfigurationException('Could not process configuration. Please check the property in error message: ' . $e->getMessage());
276+
throw new InvalidConfigurationException('Invalid configuration: ' . $e->getMessage());
219277
}
220278
$this->cleanupSlaveConnections();
221279
$this->cleanupConnections();
@@ -239,11 +297,16 @@ private function getConfigFileNamesFromDirectory(string $path): array
239297
];
240298
$dirs = array_filter($dirs, 'is_dir');
241299

242-
$fileGlob = self::CONFIG_FILE_NAME . '.{php,inc,ini,properties,yaml,yml,xml,json}{,.dist}';
300+
$fileGlob = 'p{rope,erp}l.{php,inc,ini,properties,yaml,yml,xml,json}{,.dist}';
243301
$finder = new Finder();
244302
$finder->in($dirs)->depth(0)->files()->name($fileGlob);
245303
$orderedConfigFileNames = [];
246304
foreach ($finder as $file) {
305+
$realPath = $file->getRealPath();
306+
$isExecutable = array_any(['propel', 'perpl'], fn ($cmd) => str_ends_with($realPath, "/bin/{$cmd}.php"));
307+
if ($isExecutable) {
308+
continue;
309+
}
247310
$precedence = ($file->getExtension() === 'dist') ? self::PRECEDENCE_DIST : self::PRECEDENCE_NORMAL;
248311
if (isset($orderedConfigFileNames[$precedence])) {
249312
$messageSplits = [

src/Propel/Generator/Application.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@ class Application extends SymfonyApplication
2323
#[\Override]
2424
public function doRun(InputInterface $input, OutputInterface $output): int
2525
{
26-
if (extension_loaded('xdebug')) {
26+
$command = $input->getFirstArgument();
27+
$xdebugNoWarn = in_array($command, ['completion', '_complete']);
28+
29+
if (!$xdebugNoWarn && extension_loaded('xdebug')) {
2730
$output->writeln(
28-
'<comment>You are running propel with xdebug enabled. This has a major impact on runtime performance.</comment>' . "\n",
31+
'<comment>You are running perpl with xdebug enabled. This has a major impact on runtime performance.</comment>' . "\n",
2932
);
3033
}
3134

src/Propel/Generator/Behavior/Archivable/ArchivableBehaviorObjectBuilderModifier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ public function preDelete(AbstractOMBuilder $builder): ?string
127127
if ($this->behavior->isArchiveOnDelete()) {
128128
return $this->behavior->renderTemplate('objectPreDelete', [
129129
'queryClassName' => $builder->getQueryClassName(),
130-
'isAddHooks' => $builder->getGeneratorConfig()->get()['generator']['objectModel']['addHooks'],
130+
'isAddHooks' => (bool)$builder->getGeneratorConfig()->getConfigProperty('generator.objectModel.addHooks'),
131131
]);
132132
}
133133

src/Propel/Generator/Builder/DataModelBuilder.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,26 @@ public function getTable(): Table
176176
* <code>'database.adapter.mysql.tableType</code>
177177
*
178178
* @param string $name
179+
* @param bool $isRequired
179180
*
180-
* @return string|null
181+
* @return array|scalar|null
181182
*/
182-
public function getBuildProperty(string $name): ?string
183+
public function getBuildProperty(string $name, bool $isRequired = false): mixed
183184
{
184-
if ($this->getGeneratorConfig()) {
185-
return $this->getGeneratorConfig()->getConfigProperty($name);
186-
}
185+
return $this->getGeneratorConfig()?->getConfigProperty($name, $isRequired);
186+
}
187187

188-
return null;
188+
/**
189+
* @psalm-return ($isRequired ? string : string|null)
190+
*
191+
* @param string $name
192+
* @param bool $isRequired
193+
*
194+
* @return string|null
195+
*/
196+
public function getBuildPropertyString(string $name, bool $isRequired = false): string|null
197+
{
198+
return $this->getGeneratorConfig()->getConfigPropertyString($name, $isRequired);
189199
}
190200

191201
/**
@@ -325,7 +335,7 @@ public function quoteIdentifier(string $text): string
325335
*/
326336
public function prefixClassName(string $identifier): string
327337
{
328-
return $this->getBuildProperty('generator.objectModel.classPrefix') . $identifier;
338+
return $this->getBuildPropertyString('generator.objectModel.classPrefix', true) . $identifier;
329339
}
330340

331341
/**
@@ -707,6 +717,6 @@ public function resolveColumnDateTimeClass(Column $column): string
707717
return $column->getPhpType();
708718
}
709719

710-
return $this->getBuildProperty('generator.dateTime.dateTimeClass') ?: '\DateTime';
720+
return $this->getBuildPropertyString('generator.dateTime.dateTimeClass') ?: '\DateTime';
711721
}
712722
}

0 commit comments

Comments
 (0)