Download the PHP package wp-cli/wp-config-transformer without Composer

On this page you can find all versions of the php package wp-cli/wp-config-transformer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package wp-config-transformer

WP Config Transformer

Programmatically edit a wp-config.php file.

Testing

Quick links: Testing

Using

Instantiate

Edit constants

Edit variables

Check for existence

Options

Special behaviors when adding or updating configs are available using the options array.

Normalization

In contrast to the "edit in place" strategy above, there is the option to normalize the output during a config update and effectively replace the existing syntax with output that adheres to WP Coding Standards.

Let's reconsider a poorly-formatted example:

This time running:

Now we will get an output of:

Nice!

Raw format

Suppose you want to change your ABSPATH config (gasp!). To do that, we can run:

The raw option means that instead of placing the value inside the config as a string "dirname( __FILE__ ) . '/somewhere/else/'" it will become unquoted (and executable) syntax dirname( __FILE__ ) . '/somewhere/else/'.

Anchor string

The anchor string is the piece of text that additions will be anchored to.

Anchor placement

By default, new configs will be placed before the anchor string.

Anchor separator

By default, the separator between a new config and its anchor string is an EOL ("\n" on *nix and "\r\n" on Windows).

Add if missing

By default, when attempting to update a config that doesn't exist, one will be added. This behavior can be overridden by specifying the add option and setting it to false.

If the constant FOO exists, it will be updated in-place. And if not, the update will return false:

How it works

Parsing configs

Constants: https://regex101.com/r/6AeNGP/4

Variables: https://regex101.com/r/cSLZZz/4

Editing in place

Due to the unsemantic nature of the wp-config.php file, and PHP's loose syntax in general, the WP Config Transformer takes an "edit in place" strategy in order to preserve the original formatting and whatever other obscurities may be taking place in the block. After all, we only care about transforming values, not constant or variable names.

To achieve this, the following steps are performed:

  1. A PHP block containing a config is split into distinct parts.
  2. Only the part containing the config value is targeted for replacement.
  3. The parts are reassembled with the new value in place.
  4. The old PHP block is replaced with the new PHP block.

Consider the following horrifically-valid PHP block, that also happens to be using the optional (and rare) 3rd argument for constant case-sensitivity:

The "edit in place" strategy means that running:

Will give us a result that safely changes only the value, leaving the formatting and additional argument(s) unscathed:

Option forwarding

Any option supported by the add() method can also be passed through the update() method and forwarded along when the config does not exist.

For example, you want to update the FOO constant in-place if it exists, otherwise it should be added to a special location:

Which has the same effect as the long-form logic:

Of course the exception to this is if you are using the add => false option, in which case the update will return false and no config will be added.

Known issues

  1. Regex will only match one config definition per line.

CORRECT

INCORRECT

  1. If the third argument in define() is used, it must be a boolean.

CORRECT

INCORRECT

Testing


All versions of wp-config-transformer with dependencies

PHP Build Version
Package Version
Requires php Version ^5.6 || ^7.0 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package wp-cli/wp-config-transformer contains the following files

Loading the files please wait ....