summaryrefslogtreecommitdiffstats
path: root/psysh-bin-autoload.patch
blob: 42b544e286fd8317268f53dd2f916f250f944a46 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
diff --git a/bin/psysh b/bin/psysh
index 0829481..2e73ad5 100755
--- a/bin/psysh
+++ b/bin/psysh
@@ -10,101 +10,7 @@
  * 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);
-    }
-/* >>> */
-}
+require_once '__PHPDIR__/Psy/autoload.php';
 
 // If the psysh binary was included directly, assume they just wanted an
 // autoloader and bail early.
@@ -128,21 +34,5 @@ if (Psy\Shell::isIncluded($trace)) {
 // 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());