Skip to content

Commit 87897c2

Browse files
committed
Fix issue with different PHP-Parser version in the project
1 parent e2b2a44 commit 87897c2

File tree

4 files changed

+39
-0
lines changed

4 files changed

+39
-0
lines changed

bin/phpstan

+1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ use PHPStan\Command\WorkerCommand;
5959
require_once __DIR__ . '/../vendor/jetbrains/phpstorm-stubs/PhpStormStubsMap.php';
6060
require_once __DIR__ . '/../vendor/react/promise-timer/src/functions_include.php';
6161
require_once __DIR__ . '/../vendor/react/promise/src/functions_include.php';
62+
require_once __DIR__ . '/../preload.php';
6263

6364
$version = 'Version unknown';
6465
try {

compiler/build/box.json

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"compactors": [
77
"KevinGH\\Box\\Compactor\\PhpScoper"
88
],
9+
"files": [
10+
"preload.php"
11+
],
912
"directories": [
1013
"conf",
1114
"src",

compiler/src/Console/CompileCommand.php

+34
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4747
{
4848
$this->processFactory->setOutput($output);
4949

50+
$this->buildPreloadScript();
5051
$this->fixComposerJson($this->buildDir);
5152
$this->renamePhpStormStubs();
5253

@@ -110,4 +111,37 @@ private function renamePhpStormStubs(): void
110111
}
111112
}
112113

114+
private function buildPreloadScript(): void
115+
{
116+
$vendorDir = $this->buildDir . '/vendor';
117+
if (!is_dir($vendorDir . '/nikic/php-parser/lib/PhpParser')) {
118+
return;
119+
}
120+
121+
$preloadScript = $this->buildDir . '/preload.php';
122+
$template = <<<'php'
123+
<?php declare(strict_types = 1);
124+
125+
%s
126+
php;
127+
$finder = \Symfony\Component\Finder\Finder::create();
128+
$root = realpath(__DIR__ . '/../../..');
129+
if ($root === false) {
130+
return;
131+
}
132+
$output = '';
133+
foreach ($finder->files()->name('*.php')->in([
134+
$vendorDir . '/nikic/php-parser/lib/PhpParser',
135+
]) as $phpFile) {
136+
$realPath = $phpFile->getRealPath();
137+
if ($realPath === false) {
138+
return;
139+
}
140+
$path = substr($realPath, strlen($root));
141+
$output .= 'require_once __DIR__ . ' . var_export($path, true) . ';' . "\n";
142+
}
143+
144+
file_put_contents($preloadScript, sprintf($template, $output));
145+
}
146+
113147
}

preload.php

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php declare(strict_types = 1);

0 commit comments

Comments
 (0)