25 lines
1.3 KiB
PHP
25 lines
1.3 KiB
PHP
<?php
|
|
|
|
// Writes engine/stubs/opengl.stub.php and openal.stub.php from the loaded extensions (reflection), for phpstan
|
|
// and IDEs. Run in the desktop image: bin/jumphp php . tools/gl-stubs.php
|
|
foreach (['OpenGL' => 'opengl', 'openal' => 'openal'] as $ext => $file) {
|
|
$r = new ReflectionExtension($ext);
|
|
$out = "<?php\n// Generated by tools/gl-stubs.php from the $ext extension (" . ($ext === 'OpenGL'
|
|
? 'Ponup/php-opengl + docker/ext/php-opengl.patch' : 'Ponup/php-openal') . "): signatures for phpstan / IDEs.\n\n";
|
|
foreach ($r->getConstants() as $name => $value) {
|
|
$out .= "const $name = " . var_export($value, true) . ";\n";
|
|
}
|
|
$out .= "\n";
|
|
$functions = $r->getFunctions();
|
|
ksort($functions);
|
|
foreach ($functions as $f) {
|
|
$params = [];
|
|
foreach ($f->getParameters() as $p) {
|
|
$params[] = ($p->isPassedByReference() ? '&' : '') . ($p->isVariadic() ? '...' : '') . '$' . $p->getName()
|
|
. ($p->isOptional() && !$p->isVariadic() ? ' = null' : '');
|
|
}
|
|
$out .= "/** @return mixed */\nfunction {$f->getName()}(" . implode(', ', $params) . ") {}\n";
|
|
}
|
|
file_put_contents(__DIR__ . "/../engine/stubs/$file.stub.php", $out);
|
|
echo "$file: " . count($functions) . " functions, " . count($r->getConstants()) . " constants\n";
|
|
}
|