Skip to content

Commit

Permalink
BetterReflectionSourceLocator - playground mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Jul 23, 2024
1 parent ed7524a commit 7d1bde4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ parameters:
editorUrlTitle: null
errorFormat: null
sysGetTempDir: ::sys_get_temp_dir()
sourceLocatorPlaygroundMode: false
pro:
dnsServers:
- '1.1.1.2'
Expand Down Expand Up @@ -2063,6 +2064,7 @@ services:
analysedPaths: %analysedPaths%
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
analysedPathsFromConfig: %analysedPathsFromConfig%
playgroundMode: %sourceLocatorPlaygroundMode%

-
implement: PHPStan\Reflection\BetterReflection\BetterReflectionProviderFactory
Expand Down
3 changes: 3 additions & 0 deletions conf/parametersSchema.neon
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ parametersSchema:
env: arrayOf(string(), anyOf(int(), string()))
sysGetTempDir: string()

# playground mode
sourceLocatorPlaygroundMode: bool()

# irrelevant Nette parameters
debugMode: bool()
productionMode: bool()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function __construct(
private array $analysedPaths,
private array $composerAutoloaderProjectPaths,
private array $analysedPathsFromConfig,
private bool $playgroundMode, // makes all PHPStan classes in the PHAR discoverable with PSR-4
)
{
}
Expand Down Expand Up @@ -112,11 +113,16 @@ public function create(): SourceLocator
if (extension_loaded('phar')) {
$pharProtocolPath = Phar::running();
if ($pharProtocolPath !== '') {
$mappings = [
'PHPStan\\BetterReflection\\' => [$pharProtocolPath . '/vendor/ondrejmirtes/better-reflection/src/'],
];
if ($this->playgroundMode) {
$mappings['PHPStan\\'] = [$pharProtocolPath . '/src/'];
} else {
$mappings['PHPStan\\Testing\\'] = [$pharProtocolPath . '/src/Testing/'];
}
$fileLocators[] = $this->optimizedPsrAutoloaderLocatorFactory->create(
Psr4Mapping::fromArrayMappings([
'PHPStan\\Testing\\' => [$pharProtocolPath . '/src/Testing/'],
'PHPStan\\BetterReflection\\' => [$pharProtocolPath . '/vendor/ondrejmirtes/better-reflection/src/'],
]),
Psr4Mapping::fromArrayMappings($mappings),
);
}
}
Expand Down

0 comments on commit 7d1bde4

Please sign in to comment.