first commit
This commit is contained in:
159
vendor/psy/psysh/bin/fetch-manual
vendored
Executable file
159
vendor/psy/psysh/bin/fetch-manual
vendored
Executable file
@ -0,0 +1,159 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2025 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
// Fetch the latest manual from GitHub releases for bundling in PHAR builds
|
||||
|
||||
const RELEASES_URL = 'https://api.github.com/repos/bobthecow/psysh-manual/releases';
|
||||
|
||||
function fetchLatestManual(): bool {
|
||||
echo "Fetching latest manual release info...\n";
|
||||
|
||||
$context = stream_context_create([
|
||||
'http' => [
|
||||
'user_agent' => 'PsySH Manual Fetcher',
|
||||
'timeout' => 10.0,
|
||||
],
|
||||
]);
|
||||
|
||||
$result = @file_get_contents(RELEASES_URL, false, $context);
|
||||
if (!$result) {
|
||||
echo "Failed to fetch releases from GitHub\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
$releases = json_decode($result, true);
|
||||
if (!$releases || !is_array($releases)) {
|
||||
echo "Invalid response from GitHub releases API\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Find the first release with a manifest
|
||||
foreach ($releases as $release) {
|
||||
$manifest = fetchManifest($release, $context);
|
||||
if ($manifest === null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find English PHP format manual in the manifest
|
||||
foreach ($manifest['manuals'] as $manual) {
|
||||
if ($manual['lang'] === 'en' && $manual['format'] === 'php') {
|
||||
echo "Found manual v{$manual['version']} (en, php format)\n";
|
||||
|
||||
// Find the download URL for the manual
|
||||
$filename = sprintf('psysh-manual-v%s-en.tar.gz', $manual['version']);
|
||||
$downloadUrl = null;
|
||||
|
||||
foreach ($release['assets'] as $asset) {
|
||||
if ($asset['name'] === $filename) {
|
||||
$downloadUrl = $asset['browser_download_url'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ($downloadUrl === null) {
|
||||
echo "Could not find download URL for $filename\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Download and extract the manual
|
||||
return downloadAndExtractManual($downloadUrl, $filename, $context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
echo "No English PHP manual found in releases\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
function fetchManifest(array $release, $context): ?array {
|
||||
foreach ($release['assets'] as $asset) {
|
||||
if ($asset['name'] === 'manifest.json') {
|
||||
$manifestContent = @file_get_contents($asset['browser_download_url'], false, $context);
|
||||
if ($manifestContent) {
|
||||
return json_decode($manifestContent, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function downloadAndExtractManual(string $downloadUrl, string $filename, $context): bool {
|
||||
echo "Downloading $filename...\n";
|
||||
|
||||
$tempFile = sys_get_temp_dir() . '/' . $filename;
|
||||
$content = @file_get_contents($downloadUrl, false, $context);
|
||||
|
||||
if (!$content) {
|
||||
echo "Failed to download manual\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!file_put_contents($tempFile, $content)) {
|
||||
echo "Failed to save manual to $tempFile\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
echo "Extracting manual...\n";
|
||||
|
||||
// Create temp directory for extraction
|
||||
$tempDir = sys_get_temp_dir() . '/psysh-manual-' . uniqid();
|
||||
if (!mkdir($tempDir)) {
|
||||
echo "Failed to create temp directory\n";
|
||||
unlink($tempFile);
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// Extract using PharData
|
||||
$phar = new PharData($tempFile);
|
||||
$phar->extractTo($tempDir);
|
||||
|
||||
// Find the php_manual.php file
|
||||
$extractedFile = $tempDir . '/php_manual.php';
|
||||
if (!file_exists($extractedFile)) {
|
||||
echo "php_manual.php not found in extracted archive\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
// Copy to current directory
|
||||
if (!copy($extractedFile, 'php_manual.php')) {
|
||||
echo "Failed to copy manual to current directory\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
echo "Successfully fetched manual to php_manual.php\n";
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
echo "Failed to extract manual: " . $e->getMessage() . "\n";
|
||||
return false;
|
||||
} finally {
|
||||
// Clean up
|
||||
@unlink($tempFile);
|
||||
removeDirectory($tempDir);
|
||||
}
|
||||
}
|
||||
|
||||
function removeDirectory(string $dir) {
|
||||
if (!is_dir($dir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$files = array_diff(scandir($dir), ['.', '..']);
|
||||
foreach ($files as $file) {
|
||||
$path = $dir . '/' . $file;
|
||||
is_dir($path) ? removeDirectory($path) : unlink($path);
|
||||
}
|
||||
rmdir($dir);
|
||||
}
|
||||
|
||||
// Main execution
|
||||
exit(fetchLatestManual() ? 0 : 1);
|
||||
148
vendor/psy/psysh/bin/psysh
vendored
Executable file
148
vendor/psy/psysh/bin/psysh
vendored
Executable file
@ -0,0 +1,148 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2025 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
// Try to find an autoloader for a local psysh version.
|
||||
// We'll wrap this whole mess in a Closure so it doesn't leak any globals.
|
||||
call_user_func(function () {
|
||||
$cwd = null;
|
||||
|
||||
// Find the cwd arg (if present)
|
||||
$argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
|
||||
foreach ($argv as $i => $arg) {
|
||||
if ($arg === '--cwd') {
|
||||
if ($i >= count($argv) - 1) {
|
||||
fwrite(STDERR, 'Missing --cwd argument.' . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
$cwd = $argv[$i + 1];
|
||||
break;
|
||||
}
|
||||
|
||||
if (preg_match('/^--cwd=/', $arg)) {
|
||||
$cwd = substr($arg, 6);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Or fall back to the actual cwd
|
||||
if (!isset($cwd)) {
|
||||
$cwd = getcwd();
|
||||
}
|
||||
|
||||
$cwd = str_replace('\\', '/', $cwd);
|
||||
|
||||
$chunks = explode('/', $cwd);
|
||||
while (!empty($chunks)) {
|
||||
$path = implode('/', $chunks);
|
||||
$prettyPath = $path;
|
||||
if (isset($_SERVER['HOME']) && $_SERVER['HOME']) {
|
||||
$prettyPath = preg_replace('/^' . preg_quote($_SERVER['HOME'], '/') . '/', '~', $path);
|
||||
}
|
||||
|
||||
// Find composer.json
|
||||
if (is_file($path . '/composer.json')) {
|
||||
if ($cfg = json_decode(file_get_contents($path . '/composer.json'), true)) {
|
||||
if (isset($cfg['name']) && $cfg['name'] === 'psy/psysh') {
|
||||
// We're inside the psysh project. Let's use the local Composer autoload.
|
||||
if (is_file($path . '/vendor/autoload.php')) {
|
||||
if (realpath($path) !== realpath(__DIR__ . '/..')) {
|
||||
fwrite(STDERR, 'Using local PsySH version at ' . $prettyPath . PHP_EOL);
|
||||
}
|
||||
|
||||
require $path . '/vendor/autoload.php';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Or a composer.lock
|
||||
if (is_file($path . '/composer.lock')) {
|
||||
if ($cfg = json_decode(file_get_contents($path . '/composer.lock'), true)) {
|
||||
foreach (array_merge($cfg['packages'], $cfg['packages-dev']) as $pkg) {
|
||||
if (isset($pkg['name']) && $pkg['name'] === 'psy/psysh') {
|
||||
// We're inside a project which requires psysh. We'll use the local Composer autoload.
|
||||
if (is_file($path . '/vendor/autoload.php')) {
|
||||
if (realpath($path . '/vendor') !== realpath(__DIR__ . '/../../..')) {
|
||||
fwrite(STDERR, 'Using local PsySH version at ' . $prettyPath . PHP_EOL);
|
||||
}
|
||||
|
||||
require $path . '/vendor/autoload.php';
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
array_pop($chunks);
|
||||
}
|
||||
});
|
||||
|
||||
// We didn't find an autoloader for a local version, so use the autoloader that
|
||||
// came with this script.
|
||||
if (!class_exists('Psy\Shell')) {
|
||||
/* <<< */
|
||||
if (is_file(__DIR__ . '/../vendor/autoload.php')) {
|
||||
require __DIR__ . '/../vendor/autoload.php';
|
||||
} elseif (is_file(__DIR__ . '/../../../autoload.php')) {
|
||||
require __DIR__ . '/../../../autoload.php';
|
||||
} else {
|
||||
fwrite(STDERR, 'PsySH dependencies not found, be sure to run `composer install`.' . PHP_EOL);
|
||||
fwrite(STDERR, 'See https://getcomposer.org to get Composer.' . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
/* >>> */
|
||||
}
|
||||
|
||||
// If the psysh binary was included directly, assume they just wanted an
|
||||
// autoloader and bail early.
|
||||
//
|
||||
// Keep this PHP 5.3 and 5.4 code around for a while in case someone is using a
|
||||
// globally installed psysh as a bin launcher for older local versions.
|
||||
if (PHP_VERSION_ID < 50306) {
|
||||
$trace = debug_backtrace();
|
||||
} elseif (PHP_VERSION_ID < 50400) {
|
||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
|
||||
} else {
|
||||
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||
}
|
||||
|
||||
if (Psy\Shell::isIncluded($trace)) {
|
||||
unset($trace);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Clean up after ourselves.
|
||||
unset($trace);
|
||||
|
||||
// If the local version is too old, we can't do this
|
||||
if (!function_exists('Psy\bin')) {
|
||||
$argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
|
||||
$first = array_shift($argv);
|
||||
if (preg_match('/php(\.exe)?$/', $first)) {
|
||||
array_shift($argv);
|
||||
}
|
||||
array_unshift($argv, 'vendor/bin/psysh');
|
||||
|
||||
fwrite(STDERR, 'A local PsySH dependency was found, but it cannot be loaded. Please update to' . PHP_EOL);
|
||||
fwrite(STDERR, 'the latest version, or run the local copy directly, e.g.:' . PHP_EOL);
|
||||
fwrite(STDERR, PHP_EOL);
|
||||
fwrite(STDERR, ' ' . implode(' ', $argv) . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
// And go!
|
||||
call_user_func(Psy\bin());
|
||||
Reference in New Issue
Block a user