Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / psy / psysh / bin / psysh
1 #!/usr/bin/env php
2 <?php
3
4 /*
5  * This file is part of Psy Shell.
6  *
7  * (c) 2012-2017 Justin Hileman
8  *
9  * For the full copyright and license information, please view the LICENSE
10  * file that was distributed with this source code.
11  */
12
13 // Try to find an autoloader for a local psysh version.
14 // We'll wrap this whole mess in a Closure so it doesn't leak any globals.
15 call_user_func(function () {
16     $cwd = null;
17
18     // Find the cwd arg (if present)
19     $argv = isset($_SERVER['argv']) ? $_SERVER['argv'] : array();
20     foreach ($argv as $i => $arg) {
21         if ($arg === '--cwd') {
22             if ($i >= count($argv) - 1) {
23                 echo 'Missing --cwd argument.' . PHP_EOL;
24                 exit(1);
25             }
26             $cwd = $argv[$i + 1];
27             break;
28         }
29
30         if (preg_match('/^--cwd=/', $arg)) {
31             $cwd = substr($arg, 6);
32             break;
33         }
34     }
35
36     // Or fall back to the actual cwd
37     if (!isset($cwd)) {
38         $cwd = getcwd();
39     }
40
41     $cwd = str_replace('\\', '/', $cwd);
42
43     $chunks = explode('/', $cwd);
44     while (!empty($chunks)) {
45         $path = implode('/', $chunks);
46
47         // Find composer.json
48         if (is_file($path . '/composer.json')) {
49             if ($cfg = json_decode(file_get_contents($path . '/composer.json'), true)) {
50                 if (isset($cfg['name']) && $cfg['name'] === 'psy/psysh') {
51                     // We're inside the psysh project. Let's use the local
52                     // Composer autoload.
53                     if (is_file($path . '/vendor/autoload.php')) {
54                         require $path . '/vendor/autoload.php';
55                     }
56
57                     return;
58                 }
59             }
60         }
61
62         // Or a composer.lock
63         if (is_file($path . '/composer.lock')) {
64             if ($cfg = json_decode(file_get_contents($path . '/composer.lock'), true)) {
65                 foreach (array_merge($cfg['packages'], $cfg['packages-dev']) as $pkg) {
66                     if (isset($pkg['name']) && $pkg['name'] === 'psy/psysh') {
67                         // We're inside a project which requires psysh. We'll
68                         // use the local Composer autoload.
69                         if (is_file($path . '/vendor/autoload.php')) {
70                             require $path . '/vendor/autoload.php';
71                         }
72
73                         return;
74                     }
75                 }
76             }
77         }
78
79         array_pop($chunks);
80     }
81 });
82
83 // We didn't find an autoloader for a local version, so use the autoloader that
84 // came with this script.
85 if (!class_exists('Psy\Shell')) {
86 /* <<< */
87     if (is_file(__DIR__ . '/../vendor/autoload.php')) {
88         require __DIR__ . '/../vendor/autoload.php';
89     } elseif (is_file(__DIR__ . '/../../../autoload.php')) {
90         require __DIR__ . '/../../../autoload.php';
91     } else {
92         echo 'PsySH dependencies not found, be sure to run `composer install`.' . PHP_EOL;
93         echo 'See https://getcomposer.org to get Composer.' . PHP_EOL;
94         exit(1);
95     }
96 /* >>> */
97 }
98
99 // If the psysh binary was included directly, assume they just wanted an
100 // autoloader and bail early.
101 if (version_compare(PHP_VERSION, '5.3.6', '<')) {
102     $trace = debug_backtrace();
103 } elseif (version_compare(PHP_VERSION, '5.4.0', '<')) {
104     $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
105 } else {
106     $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 1);
107 }
108
109 if (Psy\Shell::isIncluded($trace)) {
110     unset($trace);
111
112     return;
113 }
114
115 // Clean up after ourselves.
116 unset($trace);
117
118 // If the local version is too old, we can't do this
119 if (!function_exists('Psy\bin')) {
120     $argv = $_SERVER['argv'];
121     $first = array_shift($argv);
122     if (preg_match('/php(\.exe)?$/', $first)) {
123         array_shift($argv);
124     }
125     array_unshift($argv, 'vendor/bin/psysh');
126
127     echo 'A local PsySH dependency was found, but it cannot be loaded. Please update to' . PHP_EOL;
128     echo 'the latest version, or run the local copy directly, e.g.:' . PHP_EOL;
129     echo PHP_EOL;
130     echo '    ' . implode(' ', $argv) . PHP_EOL;
131     exit(1);
132 }
133
134 // And go!
135 call_user_func(Psy\bin());