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

Wrong statement in the configuration doc page #105

Closed
jfradj opened this issue Nov 7, 2022 · 4 comments
Closed

Wrong statement in the configuration doc page #105

jfradj opened this issue Nov 7, 2022 · 4 comments
Assignees

Comments

@jfradj
Copy link

jfradj commented Nov 7, 2022

Hello,

https://odan.github.io/slim4-skeleton/configuration.html states that:

The configuration files are loaded in this order:

Load default settings from: config/defaults.php

If the environment variable APP_ENV is defined, load the environment specific file, e.g. config/local.{env}.php

Load secret credentials (if file exists) from:

  • config/env.php
  • config/../../env.php

Which is not correct.
The PHP glob() function used, returns file paths alphabetically ordered, thus the secret credentials file (env.php) will be loaded BEFORE the environment specific file (local.{env}.php)

I think the issue isn't really in the documentation page, since it's the expected behavior.
The issue is in the config/settings.php file using the glob function thus loosing any kind of control on the load ordering

Regards,
Johann

@jfradj
Copy link
Author

jfradj commented Nov 7, 2022

The following code replacement will fix the issue.

// Overwrite default settings with environment specific local settings
$configFiles = [
    __DIR__ . "/local.{$_ENV['APP_ENV']}.php",
    __DIR__ . '/env.php',
    __DIR__ . '/../../env.php',
];

foreach ($configFiles as $configFile) {
    if (!file_exists($configFile)) {
        continue;
    }

    $local = require $configFile;
    if (is_callable($local)) {
        $settings = $local($settings);
    }
}

@odan
Copy link
Owner

odan commented Nov 8, 2022

Thanks for the feedback. Your approach looks good. I will check it.

@odan odan self-assigned this Nov 8, 2022
@odan
Copy link
Owner

odan commented Nov 8, 2022

It should be fixed now. Please check the changes and give me feedback.

@odan
Copy link
Owner

odan commented Nov 9, 2022

Close this as fixed.

@odan odan closed this as completed Nov 9, 2022
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

No branches or pull requests

2 participants