-
-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Add ExtensionConfigResolver for rector/rector-installer (#6150)
Relates: 6129
- Loading branch information
1 parent
2b22e73
commit 95b31d0
Showing
3 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Bootstrap; | ||
|
||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class ExtensionConfigResolver | ||
{ | ||
/** | ||
* @param SmartFileInfo[] $configFileInfos | ||
* @return SmartFileInfo[] | ||
*/ | ||
public function appendExtensionsConfig(array $configFileInfos): array | ||
{ | ||
if (! class_exists('Rector\RectorInstaller\GeneratedConfig')) { | ||
return $configFileInfos; | ||
} | ||
|
||
$generatedConfigReflection = new \ReflectionClass('Rector\RectorInstaller\GeneratedConfig'); | ||
|
||
if ($generatedConfigReflection->getFileName() === false) { | ||
return $configFileInfos; | ||
} | ||
|
||
$generatedConfigDirectory = dirname($generatedConfigReflection->getFileName()); | ||
foreach (\Rector\RectorInstaller\GeneratedConfig::EXTENSIONS as $name => $extensionConfig) { | ||
foreach ($extensionConfig['extra']['includes'] ?? [] as $includedFile) { | ||
$includedFilePath = null; | ||
if (isset($extensionConfig['relative_install_path'])) { | ||
$includedFilePath = sprintf( | ||
'%s/%s/%s', | ||
$generatedConfigDirectory, | ||
$extensionConfig['relative_install_path'], | ||
$includedFile | ||
); | ||
if (! file_exists($includedFilePath) || ! is_readable($includedFilePath)) { | ||
$includedFilePath = null; | ||
} | ||
} | ||
|
||
if ($includedFilePath === null) { | ||
$includedFilePath = sprintf('%s/%s', $extensionConfig['install_path'], $includedFile); | ||
} | ||
$configFileInfos[] = new SmartFileInfo($includedFilePath); | ||
} | ||
} | ||
|
||
return $configFileInfos; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters