Skip to content
Permalink
Browse files

Support PhpAdapter for configurations

  • Loading branch information...
mglaman authored and ondrejmirtes committed May 31, 2019
1 parent 279b310 commit bba5b37a46ee5fc7db20239a610d9c63817b00e1
@@ -3,6 +3,7 @@
namespace PHPStan\Command;
use Nette\DI\Config\Adapters\NeonAdapter;
use Nette\DI\Config\Adapters\PhpAdapter;
use Nette\DI\Helpers;
use Nette\Schema\Context as SchemaContext;
use Nette\Schema\Processor;
@@ -330,9 +331,10 @@ private static function detectDuplicateIncludedFiles(
): void
{
$neonAdapter = new NeonAdapter();
$phpAdapter = new PhpAdapter();
$allConfigFiles = $configFiles;
foreach ($configFiles as $configFile) {
$allConfigFiles = array_merge($allConfigFiles, self::getConfigFiles($neonAdapter, $configFile, $loaderParameters));
$allConfigFiles = array_merge($allConfigFiles, self::getConfigFiles($neonAdapter, $phpAdapter, $configFile, $loaderParameters));
}
$normalized = array_map(static function (string $file) use ($fileHelper): string {
@@ -359,6 +361,7 @@ private static function detectDuplicateIncludedFiles(
private static function getConfigFiles(
NeonAdapter $neonAdapter,
PhpAdapter $phpAdapter,
string $configFile,
array $loaderParameters
): array
@@ -367,15 +370,19 @@ private static function getConfigFiles(
return [];
}
$data = $neonAdapter->load($configFile);
if (Strings::endsWith($configFile, '.php')) {
$data = $phpAdapter->load($configFile);
} else {
$data = $neonAdapter->load($configFile);
}
$allConfigFiles = [];
if (isset($data['includes'])) {
Validators::assert($data['includes'], 'list', sprintf("section 'includes' in file '%s'", $configFile));
$includes = Helpers::expand($data['includes'], $loaderParameters);
foreach ($includes as $include) {
$include = self::expandIncludedFile($include, $configFile);
$allConfigFiles[] = $include;
$allConfigFiles = array_merge($allConfigFiles, self::getConfigFiles($neonAdapter, $include, $loaderParameters));
$allConfigFiles = array_merge($allConfigFiles, self::getConfigFiles($neonAdapter, $phpAdapter, $include, $loaderParameters));
}
}
@@ -70,6 +70,16 @@ public function dataBegin(): array
[],
true,
],
[
'',
'',
__DIR__ . '/data/includePhp.neon',
null,
[
'level' => '3',
],
false,
],
];
}
@@ -0,0 +1,10 @@
<?php
return [
'parameters' => [
'level' => '3',
],
'includes' => [
'testIncludesExpand.neon'
]
];
@@ -0,0 +1,2 @@
includes:
- config.php

0 comments on commit bba5b37

Please sign in to comment.
You can’t perform that action at this time.