Skip to content

First pass at constant/variable transformation#1

Merged
schlessera merged 52 commits intowp-cli:masterfrom
frankiejarrett:master
Jan 24, 2018
Merged

First pass at constant/variable transformation#1
schlessera merged 52 commits intowp-cli:masterfrom
frankiejarrett:master

Conversation

@frankiejarrett
Copy link
Contributor

@frankiejarrett frankiejarrett commented Dec 20, 2017

@danielbachhuber API here is pretty self-explanatory. So far it seems to work pretty well.

Going continue to poke at it and get a test framework in place so we can throw in a ton of scenarios.

Examples:

$config_transformer = new WPConfigTransformer( '/path/to/wp-config.php' );
$config_transformer->exists( 'constant', 'DB_HOST' );              // Returns true
$config_transformer->add( 'constant', 'DB_HOST', 'localhost' );    // Returns false
$config_transformer->update( 'constant', 'DB_HOST', 'localhost' ); // Returns true
$config_transformer->remove( 'constant', 'DB_HOST' );              // Returns true

Examples using raw values:

$config_transformer->update( 'constant', 'FS_CHMOD_DIR', '(0755 & ~ umask())', [ 'raw' => true ] );
$config_transformer->update( 'constant', 'ABSPATH', "dirname( __FILE__ ) . '/somewhere/else/'", [ 'raw' => true ] );
$config_transformer->update( 'constant', 'WP_DEBUG', 'true', [ 'raw' => true ] );
$config_transformer->update( 'constant', 'FOO', "array( 'baz', 'qux' )", [ 'raw' => true ] );
$config_transformer->update( 'constant', 'BAR', 'null', [ 'raw' => true ] );

Variables also work:

$config_transformer->update( 'variable', 'table_prefix', 'wp_foo_' );

@danielbachhuber
Copy link
Member

💯 so cool!

@frankiejarrett
Copy link
Contributor Author

Added a bunch of thoughts to the README to explain how this all works.

@schlessera
Copy link
Member

@fjarrett Looks great so far!

This will obviously need a robust set of unit tests to make sure we can rely on these changes to work across the board. You've mentioned in the description that you'll take care of tests as well, but feel free to ping me when you need help with anything!

@schlessera
Copy link
Member

Travis is missing a composer install step. That's why you're getting the error that the vendor/autoload.php file is missing.

@frankiejarrett
Copy link
Contributor Author

Thanks @schlessera! First round of changes pushed based on your feedback.

@schlessera
Copy link
Member

@fjarrett Looks good.
I think you misinterpreted my comment about the short description, though. If you click through the link I provided to WPCS, you can see that it requires the third person singular form.

So, instead of this:

Apply formatting to a config value.

WPCS requires this:

Applies formatting to a config value.

You write the short description as if the sentence would start with the pronoun it, referring to the function/method:

[It] Applies formatting to a config value.

@frankiejarrett
Copy link
Contributor Author

Travis is throwing disk quota exceeded errors - hoping that will clear up on its own...

@schlessera
Copy link
Member

Seems to have been a temporary issue, a restart got us through successfully.

@schlessera
Copy link
Member

Merging this as is so it can more easily be used and tested. Any improvements/fixes will be separate PRs.

@schlessera schlessera merged commit 8afcc5a into wp-cli:master Jan 24, 2018
@gitlost
Copy link

gitlost commented Jan 26, 2018

@schlessera so the thing to do here first is to review wp-cli/wp-config-transformer for bundling? Or has it been sufficiently reviewed and we just need to do a PR on wp-cli/wp-cli to bundle it?

(Am reviewing this PR anyway...)

Edit: meant to do this and following comment on wp-cli/config-command#44.

@gitlost
Copy link

gitlost commented Jan 26, 2018

As it's just one file and phpunit tests I'm wondering if it wouldn't be best/simplest to merge wp-cli/wp-config-transformer into this repo.....?

@schlessera
Copy link
Member

One of the original goals was to create a stand-alone library to deal with wp-config.php modifications, as having a WP-CLI command to do it is just one individual use case. There are other instances where such a library can be useful as well.

@gitlost
Copy link

gitlost commented Jan 26, 2018

Hmm, okay, but having all these separate repos is a logistical nightmare to be honest.

So this repo is reviewed and just needs to be bundled then?

Edit: And released.

(Unfortunately I'm very stuck for time today and won't get back to doing WP-CLI stuff until tonight.)

@gitlost
Copy link

gitlost commented Jan 27, 2018

Oh okay I see it's already released. And will be "bundled" with config-command as soon as wp-cli/config-command#44 is merged.

So the only (but big) to-do item is to change make-phar.php to include it?

Edit: turns out no change needed for make-phar.php.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants