update lock clucknut
All checks were successful
All checks were successful
This commit is contained in:
159
vendor/psy/psysh/bin/fetch-manual
vendored
159
vendor/psy/psysh/bin/fetch-manual
vendored
@@ -1,159 +0,0 @@
|
||||
#!/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);
|
||||
243
vendor/psy/psysh/bin/psysh
vendored
Normal file → Executable file
243
vendor/psy/psysh/bin/psysh
vendored
Normal file → Executable file
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
* This file is part of Psy Shell.
|
||||
*
|
||||
* (c) 2012-2025 Justin Hileman
|
||||
* (c) 2012-2026 Justin Hileman
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
@@ -14,6 +14,9 @@
|
||||
// We'll wrap this whole mess in a Closure so it doesn't leak any globals.
|
||||
call_user_func(function () {
|
||||
$cwd = null;
|
||||
$cwdFromArg = false;
|
||||
$forceTrust = false;
|
||||
$forceUntrust = false;
|
||||
|
||||
// Find the cwd arg (if present)
|
||||
$argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
|
||||
@@ -24,22 +27,223 @@ call_user_func(function () {
|
||||
exit(1);
|
||||
}
|
||||
$cwd = $argv[$i + 1];
|
||||
break;
|
||||
$cwdFromArg = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match('/^--cwd=/', $arg)) {
|
||||
$cwd = substr($arg, 6);
|
||||
break;
|
||||
$cwdFromArg = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($arg === '--trust-project') {
|
||||
$forceTrust = true;
|
||||
$forceUntrust = false;
|
||||
} elseif ($arg === '--no-trust-project') {
|
||||
$forceUntrust = true;
|
||||
$forceTrust = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Or fall back to the actual cwd
|
||||
if (!isset($cwd)) {
|
||||
if ($cwdFromArg) {
|
||||
if (!@chdir($cwd)) {
|
||||
fwrite(STDERR, 'Invalid --cwd directory: ' . $cwd . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to the actual cwd, or normalize the path after chdir
|
||||
if (!isset($cwd) || $cwdFromArg) {
|
||||
$cwd = getcwd();
|
||||
}
|
||||
|
||||
$cwd = str_replace('\\', '/', $cwd);
|
||||
|
||||
if ($cwdFromArg) {
|
||||
$filtered = array();
|
||||
$skipNext = false;
|
||||
foreach ($argv as $arg) {
|
||||
if ($skipNext) {
|
||||
$skipNext = false;
|
||||
continue;
|
||||
}
|
||||
if ($arg === '--cwd') {
|
||||
$skipNext = true;
|
||||
continue;
|
||||
}
|
||||
if (preg_match('/^--cwd=/', $arg)) {
|
||||
continue;
|
||||
}
|
||||
$filtered[] = $arg;
|
||||
}
|
||||
$_SERVER['argv'] = $filtered;
|
||||
$_SERVER['argc'] = count($filtered);
|
||||
$argv = $filtered;
|
||||
}
|
||||
|
||||
if (isset($_SERVER['PSYSH_TRUST_PROJECT']) && $_SERVER['PSYSH_TRUST_PROJECT'] !== '') {
|
||||
$mode = strtolower(trim($_SERVER['PSYSH_TRUST_PROJECT']));
|
||||
if (in_array($mode, array('true', '1'))) {
|
||||
$forceTrust = true;
|
||||
$forceUntrust = false;
|
||||
} elseif (in_array($mode, array('false', '0'))) {
|
||||
$forceUntrust = true;
|
||||
$forceTrust = false;
|
||||
} else {
|
||||
fwrite(STDERR, 'Invalid PSYSH_TRUST_PROJECT value: ' . $_SERVER['PSYSH_TRUST_PROJECT'] . '. Expected: true, 1, false, or 0.' . PHP_EOL);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
// Pass trust decision via env var and strip CLI flags. This allows a local
|
||||
// psysh version to read the trust state while avoiding errors on older
|
||||
// versions that don't understand --trust-project flags.
|
||||
if ($forceTrust) {
|
||||
$_SERVER['PSYSH_TRUST_PROJECT'] = 'true';
|
||||
$_ENV['PSYSH_TRUST_PROJECT'] = 'true';
|
||||
putenv('PSYSH_TRUST_PROJECT=true');
|
||||
} elseif ($forceUntrust) {
|
||||
$_SERVER['PSYSH_TRUST_PROJECT'] = 'false';
|
||||
$_ENV['PSYSH_TRUST_PROJECT'] = 'false';
|
||||
putenv('PSYSH_TRUST_PROJECT=false');
|
||||
}
|
||||
|
||||
if ($forceTrust || $forceUntrust) {
|
||||
$filtered = array();
|
||||
foreach ($argv as $arg) {
|
||||
if ($arg === '--trust-project' || $arg === '--no-trust-project') {
|
||||
continue;
|
||||
}
|
||||
$filtered[] = $arg;
|
||||
}
|
||||
$_SERVER['argv'] = $filtered;
|
||||
$_SERVER['argc'] = count($filtered);
|
||||
$argv = $filtered;
|
||||
}
|
||||
|
||||
$trustedRoots = array();
|
||||
if (!$forceTrust) {
|
||||
// Find the current config directory (matching ConfigPaths logic)
|
||||
$currentConfigDir = null;
|
||||
$fallbackConfigDir = null;
|
||||
|
||||
// Windows: %APPDATA%/PsySH takes priority
|
||||
if ($currentConfigDir === null && defined('PHP_WINDOWS_VERSION_MAJOR')) {
|
||||
if (isset($_SERVER['APPDATA']) && $_SERVER['APPDATA']) {
|
||||
$dir = str_replace('\\', '/', $_SERVER['APPDATA']).'/PsySH';
|
||||
$fallbackConfigDir = $fallbackConfigDir !== null ? $fallbackConfigDir : $dir;
|
||||
if (@is_dir($dir)) {
|
||||
$currentConfigDir = $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// XDG_CONFIG_HOME/psysh
|
||||
if ($currentConfigDir === null && isset($_SERVER['XDG_CONFIG_HOME']) && $_SERVER['XDG_CONFIG_HOME']) {
|
||||
$dir = rtrim(str_replace('\\', '/', $_SERVER['XDG_CONFIG_HOME']), '/').'/psysh';
|
||||
$fallbackConfigDir = $fallbackConfigDir !== null ? $fallbackConfigDir : $dir;
|
||||
if (@is_dir($dir)) {
|
||||
$currentConfigDir = $dir;
|
||||
}
|
||||
}
|
||||
|
||||
// HOME/.config/psysh (default XDG location)
|
||||
if ($currentConfigDir === null && isset($_SERVER['HOME']) && $_SERVER['HOME']) {
|
||||
$home = rtrim(str_replace('\\', '/', $_SERVER['HOME']), '/');
|
||||
|
||||
$dir = $home.'/.config/psysh';
|
||||
$fallbackConfigDir = $fallbackConfigDir !== null ? $fallbackConfigDir : $dir;
|
||||
if (@is_dir($dir)) {
|
||||
$currentConfigDir = $dir;
|
||||
}
|
||||
|
||||
// legacy
|
||||
if ($currentConfigDir === null) {
|
||||
$dir = $home.'/.psysh';
|
||||
if (@is_dir($dir)) {
|
||||
$currentConfigDir = $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Windows: HOMEDRIVE/HOMEPATH fallback
|
||||
if ($currentConfigDir === null && defined('PHP_WINDOWS_VERSION_MAJOR')) {
|
||||
if (isset($_SERVER['HOMEDRIVE']) && isset($_SERVER['HOMEPATH']) && $_SERVER['HOMEDRIVE'] && $_SERVER['HOMEPATH']) {
|
||||
$dir = rtrim(str_replace('\\', '/', $_SERVER['HOMEDRIVE'].'/'.$_SERVER['HOMEPATH']), '/').'/.psysh';
|
||||
if (@is_dir($dir)) {
|
||||
$currentConfigDir = $dir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Fall back to the first candidate directory if none exist yet
|
||||
if ($currentConfigDir === null) {
|
||||
$currentConfigDir = $fallbackConfigDir;
|
||||
}
|
||||
|
||||
if ($currentConfigDir !== null) {
|
||||
$trustFile = $currentConfigDir.'/trusted_projects.json';
|
||||
if (is_file($trustFile)) {
|
||||
$contents = file_get_contents($trustFile);
|
||||
if ($contents !== false && $contents !== '') {
|
||||
$data = json_decode($contents, true);
|
||||
if (is_array($data)) {
|
||||
foreach ($data as $dir) {
|
||||
if (!is_string($dir) || $dir === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$real = realpath($dir);
|
||||
if ($real !== false) {
|
||||
$dir = $real;
|
||||
}
|
||||
|
||||
$trustedRoots[] = str_replace('\\', '/', $dir);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Composer-generated bin proxies expose `_composer_autoload_path`, which points
|
||||
// at the autoloader for the *current* project invoking `vendor/bin/psysh`.
|
||||
// We use this to distinguish "already running via this project's local psysh"
|
||||
// from "global psysh trying to hop into some other project's local psysh".
|
||||
$proxyAutoloadPath = null;
|
||||
if (isset($GLOBALS['_composer_autoload_path'])
|
||||
&& is_string($GLOBALS['_composer_autoload_path'])
|
||||
&& $GLOBALS['_composer_autoload_path'] !== ''
|
||||
) {
|
||||
$proxyAutoloadPath = realpath($GLOBALS['_composer_autoload_path']);
|
||||
if ($proxyAutoloadPath === false) {
|
||||
$proxyAutoloadPath = str_replace('\\', '/', $GLOBALS['_composer_autoload_path']);
|
||||
} else {
|
||||
$proxyAutoloadPath = str_replace('\\', '/', $proxyAutoloadPath);
|
||||
}
|
||||
}
|
||||
|
||||
$isCurrentProjectAutoload = function ($projectPath) use ($proxyAutoloadPath) {
|
||||
if ($proxyAutoloadPath === null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$projectAutoloadPath = realpath($projectPath.'/vendor/autoload.php');
|
||||
if ($projectAutoloadPath === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return str_replace('\\', '/', $projectAutoloadPath) === $proxyAutoloadPath;
|
||||
};
|
||||
|
||||
$markUntrustedProject = function ($projectPath, $prettyPath) {
|
||||
fwrite(STDERR, 'Skipping local PsySH at ' . $prettyPath . ' (project is untrusted). Re-run with --trust-project to allow.' . PHP_EOL);
|
||||
$_SERVER['PSYSH_UNTRUSTED_PROJECT'] = $projectPath;
|
||||
$_ENV['PSYSH_UNTRUSTED_PROJECT'] = $projectPath;
|
||||
putenv('PSYSH_UNTRUSTED_PROJECT='.$projectPath);
|
||||
};
|
||||
|
||||
$chunks = explode('/', $cwd);
|
||||
while (!empty($chunks)) {
|
||||
$path = implode('/', $chunks);
|
||||
@@ -54,7 +258,18 @@ call_user_func(function () {
|
||||
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__ . '/..')) {
|
||||
$realPath = realpath($path);
|
||||
$realPath = $realPath ? str_replace('\\', '/', $realPath) : $path;
|
||||
$pathReal = realpath($path);
|
||||
$binReal = realpath(__DIR__ . '/..');
|
||||
$isCurrentPsysh = ($pathReal !== false && $pathReal === $binReal) || $isCurrentProjectAutoload($path);
|
||||
|
||||
if (!$isCurrentPsysh && !$forceTrust && ($forceUntrust || !in_array($realPath, $trustedRoots, true))) {
|
||||
$markUntrustedProject($realPath, $prettyPath);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$isCurrentPsysh) {
|
||||
fwrite(STDERR, 'Using local PsySH version at ' . $prettyPath . PHP_EOL);
|
||||
}
|
||||
|
||||
@@ -69,11 +284,23 @@ call_user_func(function () {
|
||||
// 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) {
|
||||
$packages = array_merge(isset($cfg['packages']) ? $cfg['packages'] : array(), isset($cfg['packages-dev']) ? $cfg['packages-dev'] : array());
|
||||
foreach ($packages 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__ . '/../../..')) {
|
||||
$realPath = realpath($path);
|
||||
$realPath = $realPath ? str_replace('\\', '/', $realPath) : $path;
|
||||
$vendorReal = realpath($path . '/vendor');
|
||||
$binVendorReal = realpath(__DIR__ . '/../../..');
|
||||
$isCurrentPsysh = ($vendorReal !== false && $vendorReal === $binVendorReal) || $isCurrentProjectAutoload($path);
|
||||
|
||||
if (!$isCurrentPsysh && !$forceTrust && ($forceUntrust || !in_array($realPath, $trustedRoots, true))) {
|
||||
$markUntrustedProject($realPath, $prettyPath);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$isCurrentPsysh) {
|
||||
fwrite(STDERR, 'Using local PsySH version at ' . $prettyPath . PHP_EOL);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user