-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathShell_Command.php
More file actions
62 lines (55 loc) · 1.45 KB
/
Shell_Command.php
File metadata and controls
62 lines (55 loc) · 1.45 KB
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
<?php
use WP_CLI\Utils;
class Shell_Command extends WP_CLI_Command {
/**
* Opens an interactive PHP console for running and testing PHP code.
*
* `wp shell` allows you to evaluate PHP statements and expressions
* interactively, from within a WordPress environment. Type a bit of code,
* hit enter, and see the code execute right before you. Because WordPress
* is loaded, you have access to all the functions, classes and globals
* that you can use within a WordPress plugin, for example.
*
* ## OPTIONS
*
* [--basic]
* : Force the use of WP-CLI's built-in PHP REPL, even if the Boris or
* PsySH PHP REPLs are available.
*
* ## EXAMPLES
*
* # Call get_bloginfo() to get the name of the site.
* $ wp shell
* wp> get_bloginfo( 'name' );
* => string(6) "WP-CLI"
*/
public function __invoke( $_, $assoc_args ) {
$class = WP_CLI\Shell\REPL::class;
$implementations = array(
\Psy\Shell::class,
\Boris\Boris::class,
WP_CLI\Shell\REPL::class,
);
if ( ! Utils\get_flag_value( $assoc_args, 'basic' ) ) {
foreach ( $implementations as $candidate ) {
if ( class_exists( $candidate ) ) {
$class = $candidate;
break;
}
}
}
/**
* @var class-string $class
*/
if ( \Psy\Shell::class === $class ) {
$shell = new Psy\Shell();
$shell->run();
} else {
/**
* @var class-string<WP_CLI\Shell\REPL> $class
*/
$repl = new $class( 'wp> ' );
$repl->start();
}
}
}