Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds new convenience methods #3

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kellymears
Copy link
Member

@kellymears kellymears commented Mar 10, 2020

In my Bedrock projects I typically extend the Config class with some simple static methods which I have found to have broad utility. It is the aim of this PR to have them integrated into the core Config class.

I think that they are a good fit for inclusion here as they promote readability while also not over-complicating or obscuring implementation details (a central tenant of the Bedrock project.)

Further I am happy to submit a PR to the Bedrock repo taking advantage of the features included here, should there be interest. Or, it could just be left to be adopted incrementally.

Note that I have not updated the test suite. Personally I think adding @covers annotations to the existing methods would be sufficient, since the new methods are simply wrapping existing methods.

Examples of the syntax this PR enables

/**
 * Configure auth keys and salts.
 */
Config::defineSet([
    'AUTH_KEY' => env('AUTH_KEY'),
    'AUTH_SALT' => env('AUTH_SALT'),
    'LOGGED_IN_KEY' => env('LOGGED_IN_KEY'),
    'LOGGED_IN_SALT' => env('LOGGED_IN_SALT'),
    'NONCE_KEY' => env('NONCE_KEY'),
    'NONCE_SALT' => env('NONCE_SALT'),
    'SECURE_AUTH_KEY' => env('SECURE_AUTH_KEY'),
    'SECURE_AUTH_SALT' => env('SECURE_AUTH_SALT'),
]);
if (Config::containsKey('DISPLAY_ERRORS')) {
    ini_set('display_errors', Config::get('DISPLAY_ERRORS'));
}
if (Config::containsKeys(['SENTRY_DSN', 'WP_ENV']) &&
    ! Config::is('WP_ENV', 'development')) {
    \Sentry\init([
        'dsn'         => Config::get('SENTRY_DSN'),
        'environment' => Config::get('WP_ENV'),
        'release'     => Config::get('GIT_SHA'),
        'error_types' => E_ALL & ~E_NOTICE & ~E_DEPRECATED,
    ]);
}

@kellymears kellymears added the enhancement New feature or request label Mar 10, 2020
@kellymears kellymears requested a review from austinpray March 10, 2020 17:00
@kellymears kellymears self-assigned this Mar 10, 2020
@coveralls
Copy link

coveralls commented Mar 10, 2020

Pull Request Test Coverage Report for Build 64

  • 0 of 7 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-29.2%) to 70.833%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/Config.php 0 7 0.0%
Totals Coverage Status
Change from base Build 61: -29.2%
Covered Lines: 17
Relevant Lines: 24

💛 - Coveralls

Copy link
Collaborator

@austinpray austinpray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!! Yeah these are definitely good updates. I added some suggestions to make the API's behavior a bit clearer in my eyes.

Add some tests 👍

src/Config.php Outdated Show resolved Hide resolved
src/Config.php Outdated Show resolved Hide resolved
src/Config.php Outdated Show resolved Hide resolved
src/Config.php Outdated Show resolved Hide resolved
Copy link
Collaborator

@austinpray austinpray left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we php 7.1+ now: wanna add a buncha type hints and stuff?

@QWp6t QWp6t requested a review from austinpray April 29, 2021 15:53
@retlehs retlehs requested review from QWp6t and Log1x and removed request for austinpray January 26, 2024 16:36
@strarsis
Copy link

This what I am using for the Redis plugin:

// Redis cache server config (WP Redis plugin)
if (env('REDIS_HOST')) {
    $_SERVER['CACHE_HOST'] = env('REDIS_HOST');
}

$_SERVER['CACHE_PORT'] = env('REDIS_PORT'); // WP Redis plugin expects a defined PORT

if (env('REDIS_PASSWORD')) {
    $_SERVER['CACHE_PASSWORD'] = env('REDIS_PASSWORD');
}
if (env('REDIS_SALT')) {
    Config::define('WP_CACHE_KEY_SALT', env('REDIS_SALT')); // salt uses a constant instead of `$_SERVER` !
}
if (env('REDIS_DB_NO')) {
    $_SERVER['CACHE_DB'] = env('REDIS_DB_NO');
}

Interestingly, WP_CACHE_KEY_SALT is expected to be a constant instead a $_SERVER variable key.
Does the convenience mechanism described above also handle those constants?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants