Skip to content

Commit c4d66fb

Browse files
Merge pull request #1 from kirtangajjar/develop
Add initial config command implementation
2 parents cc92cfa + cc01205 commit c4d66fb

File tree

7 files changed

+179
-2
lines changed

7 files changed

+179
-2
lines changed

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

0 commit comments

Comments
 (0)