Skip to content

Instantly share code, notes, and snippets.

@theodorejb
Created February 13, 2026 22:30
Show Gist options
  • Select an option

  • Save theodorejb/26416d7a79af7b0081747288f7c9ecbb to your computer and use it in GitHub Desktop.

Select an option

Save theodorejb/26416d7a79af7b0081747288f7c9ecbb to your computer and use it in GitHub Desktop.
Extract Phar dependency source code
<?php
$vendorDir = __DIR__ . '/vendor';
$pharPath = "{$vendorDir}/phpstan/phpstan/phpstan.phar";
$extractPath = "{$vendorDir}/phpstan/phpstan-src";
if (is_file($pharPath)) {
require "{$vendorDir}/autoload.php";
if (is_dir($extractPath)) {
rmdir_recursive($extractPath);
}
$phar = new Phar($pharPath);
$phar->extractTo($extractPath);
} else {
echo $pharPath . ' is not a file';
}
function rmdir_recursive(string $dir): void
{
$cmd = PHP_OS_FAMILY === 'Windows' ? 'rmdir /s /q' : 'rm -rf';
exec($cmd . ' ' . escapeshellarg($dir), $execOutput, $execRetval);
if ($execRetval !== 0) {
throw new Exception("Failed to remove directory: " . var_export($execOutput, true));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment