Skip to content

Commit c4863d4

Browse files
committed
Add initial config command
Signed-off-by: Kirtan Gajjar <kirtangajjar95@gmail.com>
1 parent cc92cfa commit c4863d4

7 files changed

Lines changed: 185 additions & 2 deletions

File tree

.editorconfig

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This file is for unifying the coding style for different editors and IDEs
2+
# editorconfig.org
3+
4+
# WordPress Coding Standards
5+
# https://make.wordpress.org/core/handbook/coding-standards/
6+
7+
root = true
8+
9+
[*]
10+
charset = utf-8
11+
end_of_line = lf
12+
insert_final_newline = true
13+
trim_trailing_whitespace = true
14+
indent_style = tab
15+
16+
[{.jshintrc,*.json,*.yml,*.feature}]
17+
indent_style = space
18+
indent_size = 2
19+
20+
[{*.txt}]
21+
end_of_line = crlf
22+
23+
[composer.json]
24+
indent_style = space
25+
indent_size = 4

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
.DS_Store
2+
node_modules/
3+
vendor/
4+
*.zip
5+
*.tar.gz
6+
*.swp
7+
*.txt
8+
*.log
9+
composer.lock
10+
.idea
11+
*.db

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# config-command

composer.json

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66
"license": "MIT",
77
"authors": [],
88
"minimum-stability": "dev",
9-
"prefer-stable": true
9+
"prefer-stable": true,
10+
"autoload": {
11+
"psr-4": {
12+
"": "src/"
13+
},
14+
"files": [ "config-command.php" ]
15+
},
16+
"extra": {
17+
"branch-alias": {
18+
"dev-master": "1.x-dev"
19+
},
20+
"bundled": true,
21+
"commands": [
22+
"config"
23+
]
24+
}
1025
}
11-

config-command.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
if ( ! class_exists( 'EE' ) ) {
4+
return;
5+
}
6+
7+
$autoload = dirname( __FILE__ ) . '/vendor/autoload.php';
8+
if ( file_exists( $autoload ) ) {
9+
require_once $autoload;
10+
}
11+
12+
EE::add_command( 'config', 'Config_Command' );

phpcs.xml.dist

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="EE">
3+
<description>WordPress Coding Standards for EE</description>
4+
5+
<!-- Show sniff codes in all reports, and progress while running -->
6+
<arg value="sp"/>
7+
<!-- Check all PHP files in directory tree by default. -->
8+
<arg name="extensions" value="php"/>
9+
<!-- Run different reports -->
10+
<arg name="report" value="full"/>
11+
<arg name="report" value="summary"/>
12+
<arg name="report" value="source"/>
13+
14+
<file>.</file>
15+
<exclude-pattern>*/ci/*</exclude-pattern>
16+
<exclude-pattern>*/features/*</exclude-pattern>
17+
<exclude-pattern>*/packages/*</exclude-pattern>
18+
<exclude-pattern>*/tests/*</exclude-pattern>
19+
<exclude-pattern>*/utils/*</exclude-pattern>
20+
<exclude-pattern>*/vendor/*</exclude-pattern>
21+
22+
<rule ref="PHPCompatibility">
23+
<!-- Polyfill package is used so array_column() is available for PHP 5.4- -->
24+
<exclude name="PHPCompatibility.PHP.NewFunctions.array_columnFound"/>
25+
<!-- Both magic quotes directives set in wp-settings-cli.php to provide consistent starting point. -->
26+
<exclude name="PHPCompatibility.PHP.DeprecatedIniDirectives.magic_quotes_runtimeDeprecatedRemoved"/>
27+
<exclude name="PHPCompatibility.PHP.DeprecatedIniDirectives.magic_quotes_sybaseDeprecatedRemoved"/>
28+
</rule>
29+
<config name="testVersion" value="7.0-"/>
30+
31+
<rule ref="WordPress-Core">
32+
<exclude name="Squiz.PHP.DisallowMultipleAssignments.Found" />
33+
<exclude name="WordPress.NamingConventions.ValidVariableName.NotSnakeCaseMemberVar" />
34+
<exclude name="WordPress.NamingConventions.ValidVariableName.MemberNotSnakeCase" />
35+
<exclude name="WordPress.NamingConventions.ValidVariableName.NotSnakeCase" />
36+
</rule>
37+
<rule ref="WordPress.Files.FileName">
38+
<properties>
39+
<property name="strict_class_file_names" value="false"/>
40+
</properties>
41+
<exclude name="WordPress.Files.FileName.NotHyphenatedLowercase" />
42+
</rule>
43+
</ruleset>

src/Config_Command.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
3+
use EE\Model\Site;
4+
use Mustangostang\Spyc;
5+
use \Symfony\Component\Filesystem\Filesystem;
6+
7+
/**
8+
* Manges global EE configuration.
9+
*
10+
* ## EXAMPLES
11+
*
12+
* # Save value in config
13+
* $ ee config set le-mail='abc@example.com' admin-email=abcd@example1.com
14+
*
15+
* # Get value from config
16+
* $ ee config get le-mail
17+
*
18+
* @package ee-cli
19+
*/
20+
class Config_Command extends EE_Command {
21+
22+
/**
23+
* @var Filesystem $fs Symfony Filesystem object.
24+
*/
25+
private $fs;
26+
27+
public function __construct() {
28+
29+
$this->fs = new Filesystem();
30+
}
31+
32+
/**
33+
* Get a config value
34+
*
35+
* ## OPTIONS
36+
*
37+
* <config-key>
38+
* : Name of config value to get
39+
*/
40+
public function get( $args, $assoc_args ) {
41+
$config_file_path = getenv( 'EE_CONFIG_PATH' ) ? getenv( 'EE_CONFIG_PATH' ) : EE_CONF_ROOT . '/config.yml';
42+
$config = Spyc::YAMLLoad( $config_file_path );
43+
44+
if ( ! isset( $config[$args[0]] ) ) {
45+
EE::error("No config value with key '$args[0]' set");
46+
}
47+
48+
EE::log( $config[$args[0]] );
49+
}
50+
51+
/**
52+
* Get a config value
53+
*
54+
* ## OPTIONS
55+
*
56+
* <config-key-value>...
57+
* : Key value pair of config to set
58+
*/
59+
public function set( $args, $assoc_args ) {
60+
$config_file_path = getenv( 'EE_CONFIG_PATH' ) ? getenv( 'EE_CONFIG_PATH' ) : EE_CONF_ROOT . '/config.yml';
61+
$config = Spyc::YAMLLoad( $config_file_path );
62+
63+
foreach ( $args as $arg ) {
64+
$key_val = explode( '=', $arg, 2 );
65+
66+
if ( count( $key_val ) < 2 ) {
67+
EE::warning( "Cannot add $arg in config as it has no corrosponding value" );
68+
continue;
69+
}
70+
71+
list( $key, $val ) = $key_val;
72+
$config[$key] = $value;
73+
}
74+
75+
$this->fs->dumpFile( $config_file_path, Spyc::YAMLDump( $config, false, false, true ) );
76+
}
77+
}

0 commit comments

Comments
 (0)