comparison vendor/psy/psysh/src/functions.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents c2387f117808
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
16 use Symfony\Component\Console\Input\InputArgument; 16 use Symfony\Component\Console\Input\InputArgument;
17 use Symfony\Component\Console\Input\InputDefinition; 17 use Symfony\Component\Console\Input\InputDefinition;
18 use Symfony\Component\Console\Input\InputOption; 18 use Symfony\Component\Console\Input\InputOption;
19 use XdgBaseDir\Xdg; 19 use XdgBaseDir\Xdg;
20 20
21 if (!function_exists('Psy\sh')) { 21 if (!\function_exists('Psy\sh')) {
22 /** 22 /**
23 * Command to return the eval-able code to startup PsySH. 23 * Command to return the eval-able code to startup PsySH.
24 * 24 *
25 * eval(\Psy\sh()); 25 * eval(\Psy\sh());
26 * 26 *
30 { 30 {
31 return 'extract(\Psy\debug(get_defined_vars(), isset($this) ? $this : @get_called_class()));'; 31 return 'extract(\Psy\debug(get_defined_vars(), isset($this) ? $this : @get_called_class()));';
32 } 32 }
33 } 33 }
34 34
35 if (!function_exists('Psy\debug')) { 35 if (!\function_exists('Psy\debug')) {
36 /** 36 /**
37 * Invoke a Psy Shell from the current context. 37 * Invoke a Psy Shell from the current context.
38 * 38 *
39 * For example: 39 * For example:
40 * 40 *
87 // @todo come up with a better way of doing this which doesn't involve injecting input :-P 87 // @todo come up with a better way of doing this which doesn't involve injecting input :-P
88 if ($sh->has('whereami')) { 88 if ($sh->has('whereami')) {
89 $sh->addInput('whereami -n2', true); 89 $sh->addInput('whereami -n2', true);
90 } 90 }
91 91
92 if (is_string($bindTo)) { 92 if (\is_string($bindTo)) {
93 $sh->setBoundClass($bindTo); 93 $sh->setBoundClass($bindTo);
94 } elseif ($bindTo !== null) { 94 } elseif ($bindTo !== null) {
95 $sh->setBoundObject($bindTo); 95 $sh->setBoundObject($bindTo);
96 } 96 }
97 97
99 99
100 return $sh->getScopeVariables(false); 100 return $sh->getScopeVariables(false);
101 } 101 }
102 } 102 }
103 103
104 if (!function_exists('Psy\info')) { 104 if (!\function_exists('Psy\info')) {
105 /** 105 /**
106 * Get a bunch of debugging info about the current PsySH environment and 106 * Get a bunch of debugging info about the current PsySH environment and
107 * configuration. 107 * configuration.
108 * 108 *
109 * If a Configuration param is passed, that configuration is stored and 109 * If a Configuration param is passed, that configuration is stored and
121 121
122 return; 122 return;
123 } 123 }
124 124
125 $xdg = new Xdg(); 125 $xdg = new Xdg();
126 $home = rtrim(str_replace('\\', '/', $xdg->getHomeDir()), '/'); 126 $home = \rtrim(\str_replace('\\', '/', $xdg->getHomeDir()), '/');
127 $homePattern = '#^' . preg_quote($home, '#') . '/#'; 127 $homePattern = '#^' . \preg_quote($home, '#') . '/#';
128 128
129 $prettyPath = function ($path) use ($homePattern) { 129 $prettyPath = function ($path) use ($homePattern) {
130 if (is_string($path)) { 130 if (\is_string($path)) {
131 return preg_replace($homePattern, '~/', $path); 131 return \preg_replace($homePattern, '~/', $path);
132 } else { 132 } else {
133 return $path; 133 return $path;
134 } 134 }
135 }; 135 };
136 136
144 'require semicolons' => $config->requireSemicolons(), 144 'require semicolons' => $config->requireSemicolons(),
145 'error logging level' => $config->errorLoggingLevel(), 145 'error logging level' => $config->errorLoggingLevel(),
146 'config file' => [ 146 'config file' => [
147 'default config file' => $prettyPath($config->getConfigFile()), 147 'default config file' => $prettyPath($config->getConfigFile()),
148 'local config file' => $prettyPath($config->getLocalConfigFile()), 148 'local config file' => $prettyPath($config->getLocalConfigFile()),
149 'PSYSH_CONFIG env' => $prettyPath(getenv('PSYSH_CONFIG')), 149 'PSYSH_CONFIG env' => $prettyPath(\getenv('PSYSH_CONFIG')),
150 ], 150 ],
151 // 'config dir' => $config->getConfigDir(), 151 // 'config dir' => $config->getConfigDir(),
152 // 'data dir' => $config->getDataDir(), 152 // 'data dir' => $config->getDataDir(),
153 // 'runtime dir' => $config->getRuntimeDir(), 153 // 'runtime dir' => $config->getRuntimeDir(),
154 ]; 154 ];
169 'update check interval' => $config->getUpdateCheck(), 169 'update check interval' => $config->getUpdateCheck(),
170 'update cache file' => $prettyPath($config->getUpdateCheckCacheFile()), 170 'update cache file' => $prettyPath($config->getUpdateCheckCacheFile()),
171 ]; 171 ];
172 172
173 if ($config->hasReadline()) { 173 if ($config->hasReadline()) {
174 $info = readline_info(); 174 $info = \readline_info();
175 175
176 $readline = [ 176 $readline = [
177 'readline available' => true, 177 'readline available' => true,
178 'readline enabled' => $config->useReadline(), 178 'readline enabled' => $config->useReadline(),
179 'readline service' => get_class($config->getReadline()), 179 'readline service' => \get_class($config->getReadline()),
180 ]; 180 ];
181 181
182 if (isset($info['library_version'])) { 182 if (isset($info['library_version'])) {
183 $readline['readline library'] = $info['library_version']; 183 $readline['readline library'] = $info['library_version'];
184 } 184 }
191 'readline available' => false, 191 'readline available' => false,
192 ]; 192 ];
193 } 193 }
194 194
195 $pcntl = [ 195 $pcntl = [
196 'pcntl available' => function_exists('pcntl_signal'), 196 'pcntl available' => \function_exists('pcntl_signal'),
197 'posix available' => function_exists('posix_getpid'), 197 'posix available' => \function_exists('posix_getpid'),
198 ]; 198 ];
199 199
200 $disabledFuncs = array_map('trim', explode(',', ini_get('disable_functions'))); 200 $disabledFuncs = \array_map('trim', \explode(',', \ini_get('disable_functions')));
201 if (in_array('pcntl_signal', $disabledFuncs) || in_array('pcntl_fork', $disabledFuncs)) { 201 if (\in_array('pcntl_signal', $disabledFuncs) || \in_array('pcntl_fork', $disabledFuncs)) {
202 $pcntl['pcntl disabled'] = true; 202 $pcntl['pcntl disabled'] = true;
203 } 203 }
204 204
205 $history = [ 205 $history = [
206 'history file' => $prettyPath($config->getHistoryFile()), 206 'history file' => $prettyPath($config->getHistoryFile()),
224 case 'built_at': 224 case 'built_at':
225 $d = new \DateTime('@' . $val); 225 $d = new \DateTime('@' . $val);
226 $val = $d->format(\DateTime::RFC2822); 226 $val = $d->format(\DateTime::RFC2822);
227 break; 227 break;
228 } 228 }
229 $key = 'db ' . str_replace('_', ' ', $key); 229 $key = 'db ' . \str_replace('_', ' ', $key);
230 $docs[$key] = $val; 230 $docs[$key] = $val;
231 } 231 }
232 } else { 232 } else {
233 $docs['db schema'] = '0.1.0'; 233 $docs['db schema'] = '0.1.0';
234 } 234 }
241 } 241 }
242 } 242 }
243 243
244 $autocomplete = [ 244 $autocomplete = [
245 'tab completion enabled' => $config->useTabCompletion(), 245 'tab completion enabled' => $config->useTabCompletion(),
246 'custom matchers' => array_map('get_class', $config->getTabCompletionMatchers()), 246 'custom matchers' => \array_map('get_class', $config->getTabCompletionMatchers()),
247 'bracketed paste' => $config->useBracketedPaste(), 247 'bracketed paste' => $config->useBracketedPaste(),
248 ]; 248 ];
249 249
250 // Shenanigans, but totally justified. 250 // Shenanigans, but totally justified.
251 if ($shell = Sudo::fetchProperty($config, 'shell')) { 251 if ($shell = Sudo::fetchProperty($config, 'shell')) {
252 $core['loop listeners'] = array_map('get_class', Sudo::fetchProperty($shell, 'loopListeners')); 252 $core['loop listeners'] = \array_map('get_class', Sudo::fetchProperty($shell, 'loopListeners'));
253 $core['commands'] = array_map('get_class', $shell->all()); 253 $core['commands'] = \array_map('get_class', $shell->all());
254 254
255 $autocomplete['custom matchers'] = array_map('get_class', Sudo::fetchProperty($shell, 'matchers')); 255 $autocomplete['custom matchers'] = \array_map('get_class', Sudo::fetchProperty($shell, 'matchers'));
256 } 256 }
257 257
258 // @todo Show Presenter / custom casters. 258 // @todo Show Presenter / custom casters.
259 259
260 return array_merge($core, compact('updates', 'pcntl', 'readline', 'history', 'docs', 'autocomplete')); 260 return \array_merge($core, \compact('updates', 'pcntl', 'readline', 'history', 'docs', 'autocomplete'));
261 } 261 }
262 } 262 }
263 263
264 if (!function_exists('Psy\bin')) { 264 if (!\function_exists('Psy\bin')) {
265 /** 265 /**
266 * `psysh` command line executable. 266 * `psysh` command line executable.
267 * 267 *
268 * @return \Closure 268 * @return \Closure
269 */ 269 */
311 if ($usageException !== null) { 311 if ($usageException !== null) {
312 echo $usageException->getMessage() . PHP_EOL . PHP_EOL; 312 echo $usageException->getMessage() . PHP_EOL . PHP_EOL;
313 } 313 }
314 314
315 $version = $shell->getVersion(); 315 $version = $shell->getVersion();
316 $name = basename(reset($_SERVER['argv'])); 316 $name = \basename(\reset($_SERVER['argv']));
317 echo <<<EOL 317 echo <<<EOL
318 $version 318 $version
319 319
320 Usage: 320 Usage:
321 $name [--version] [--help] [files...] 321 $name [--version] [--help] [files...]