-
Notifications
You must be signed in to change notification settings - Fork 975
/
DefineProtectedCommands.php
54 lines (46 loc) · 1.18 KB
/
DefineProtectedCommands.php
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
<?php
namespace WP_CLI\Bootstrap;
/**
* Class DefineProtectedCommands.
*
* Define the commands that are "protected", meaning that they shouldn't be able
* to break due to extension code.
*
* @package WP_CLI\Bootstrap
*/
final class DefineProtectedCommands implements BootstrapStep {
/**
* Process this single bootstrapping step.
*
* @param BootstrapState $state Contextual state to pass into the step.
*
* @return BootstrapState Modified state to pass to the next step.
*/
public function process( BootstrapState $state ) {
$commands = $this->get_protected_commands();
$current_command = $this->get_current_command();
if ( in_array( $current_command, $commands, true ) ) {
$state->setValue( BootstrapState::IS_PROTECTED_COMMAND, true );
}
return $state;
}
/**
* Get the lost of protected commands.
*
* @return array
*/
private function get_protected_commands() {
return array(
'cli info',
);
}
/**
* Get the current command as a string.
*
* @return string Current command to be executed.
*/
private function get_current_command() {
$runner = new RunnerInstance();
return implode( ' ', (array) $runner()->arguments );
}
}