forked from wp-cli/shell-command
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShell_Command.php
More file actions
51 lines (47 loc) · 1.21 KB
/
Shell_Command.php
File metadata and controls
51 lines (47 loc) · 1.21 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
<?php
class Shell_Command extends \WP_CLI_Command {
/**
* Interactive PHP console.
*
* `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]
* : Start in fail-safe mode, even if Boris is 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 ) {
$implementations = array(
'\\Psy\\Shell',
'\\Boris\\Boris',
'\\WP_CLI\\REPL',
);
if ( \WP_CLI\Utils\get_flag_value( $assoc_args, 'basic' ) ) {
$class = '\\WP_CLI\\REPL';
} else {
foreach ( $implementations as $candidate ) {
if ( class_exists( $candidate ) ) {
$class = $candidate;
break;
}
}
}
if ( '\\Psy\\Shell' == $class ) {
\Psy\Shell::debug();
} else {
$repl = new $class( "wp> " );
$repl->start();
}
}
}