-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathConfig_Command.php
75 lines (64 loc) · 1.47 KB
/
Config_Command.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<?php
use Mustangostang\Spyc;
use Symfony\Component\Filesystem\Filesystem;
/**
* Manges global EE configuration.
*
* @package ee-cli
*/
class Config_Command extends EE_Command {
/**
* @var Filesystem $fs Symfony Filesystem object.
*/
private $fs;
public function __construct() {
$this->fs = new Filesystem();
}
/**
* Set a config value
*
* ## OPTIONS
*
* <config-key>
* : Name of config value to get
*
* ## EXAMPLES
*
* # Get value from config
* $ ee config get le-mail
*
*/
public function get( $args, $assoc_args ) {
$config_file_path = getenv( 'EE_CONFIG_PATH' ) ? getenv( 'EE_CONFIG_PATH' ) : EE_ROOT_DIR . '/config/config.yml';
$config = Spyc::YAMLLoad( $config_file_path );
if ( ! isset( $config[ $args[0] ] ) ) {
EE::error( "No config value with key '$args[0]' set" );
}
EE::log( $config[ $args[0] ] );
}
/**
* Set a config value
*
* ## OPTIONS
*
* <key>
* : Key of config to set
*
* <value>
* : Value of config to set
*
* ## EXAMPLES
*
* # Save value in config
* $ ee config set le-mail [email protected]
*
*/
public function set( $args, $assoc_args ) {
$config_file_path = getenv( 'EE_CONFIG_PATH' ) ? getenv( 'EE_CONFIG_PATH' ) : EE_ROOT_DIR . '/config/config.yml';
$config = Spyc::YAMLLoad( $config_file_path );
$key = $args[0];
$value = $args[1];
$config[ $key ] = $value;
$this->fs->dumpFile( $config_file_path, Spyc::YAMLDump( $config, false, false, true ) );
}
}