Skip to content

Conversation

@jaxwilko
Copy link
Member

@jaxwilko jaxwilko commented Sep 3, 2025

This PR implements support for Laravel's config:cache & config:clear commands.

The configs generated are env specific, which means that if you have config/banana/app.php with banana specific configs such as in a multi site setup you can use config:cache banana to specifically generate a cached config for that env.

By default, the env used will be the one provided via APP_ENV, or if not set environments.default, or if not set the value production.

Usage

  • Generate the default config: php artisan config:cache
  • Generate a specific config: php artisan config:cache banana
  • Clear the default config: php artisan config:clear
  • Clear a specific config: php artisan config:clear banana

TODO

  • Clean up the mess I made
  • Resolve todos
  • Test extensively

If anybody from wintercms/winter#1297 (comment) or wintercms/winter#885 (comment) would like to help test, that would be massively appreciated.

@damsfx
Copy link
Contributor

damsfx commented Sep 3, 2025

@jaxwilko

Clear the default config: php artisan config:cache
Clear a specific config: php artisan config:cache banana

Might it not rather be:

  • Clear the default config: php artisan config:clear
  • Clear a specific config: php artisan config:clear banana
    ??

@jaxwilko
Copy link
Member Author

jaxwilko commented Sep 3, 2025

@jaxwilko

Clear the default config: php artisan config:cache
Clear a specific config: php artisan config:cache banana

Might it not rather be:

  • Clear the default config: php artisan config:clear
  • Clear a specific config: php artisan config:clear banana
    ??

You are 100% correct, was in a rush to pick up my car from the garage, thank you ♥️

@LukeTowers LukeTowers requested a review from Copilot September 3, 2025 21:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements Laravel-style config:cache and config:clear commands for Winter CMS with environment-specific configuration caching. The implementation allows generating cached configs for specific environments (e.g., config:cache banana) while maintaining backward compatibility with default behavior.

Key changes:

  • Environment-specific cached config file naming (e.g., production.config.php, banana.config.php)
  • Support for environment arguments in both cache and clear commands
  • Modified configuration loading to check for cached configs before falling back to file-based loading

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Foundation/Application.php Updates cached config path to include environment name
src/Foundation/Console/ConfigCacheCommand.php Replaces warning with full implementation supporting environment-specific caching
src/Foundation/Console/ConfigClearCommand.php Replaces warning with implementation to clear environment-specific cached configs
src/Foundation/Bootstrap/LoadConfiguration.php Adds logic to load from cached config files when available
src/Config/Repository.php Modifies constructor to accept pre-loaded config items
tests/Foundation/ApplicationTest.php Updates tests to reflect new environment-specific config paths

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +26 to +31
$configPath = realpath(
dirname($this->laravel->getCachedConfigPath())
. DIRECTORY_SEPARATOR
. $this->argument('env')
. '.config.php'
);
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

The realpath() function will return false if the file doesn't exist, which could cause issues when trying to delete a non-existent config file. Consider using dirname($this->laravel->getCachedConfigPath()) . DIRECTORY_SEPARATOR . $this->argument('env') . '.config.php' directly without realpath().

Suggested change
$configPath = realpath(
dirname($this->laravel->getCachedConfigPath())
. DIRECTORY_SEPARATOR
. $this->argument('env')
. '.config.php'
);
$configPath = dirname($this->laravel->getCachedConfigPath())
. DIRECTORY_SEPARATOR
. $this->argument('env')
. '.config.php';

Copilot uses AI. Check for mistakes.
Comment on lines +115 to +117
catch (Exception $ex) {
//
}
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

Empty catch blocks make debugging difficult. Consider logging the exception or adding a comment explaining why the exception is being silently ignored.

Copilot uses AI. Check for mistakes.
Comment on lines +123 to +125
catch (Exception $ex) {
//
}
Copy link

Copilot AI Sep 3, 2025

Choose a reason for hiding this comment

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

Empty catch blocks make debugging difficult. Consider logging the exception or adding a comment explaining why the exception is being silently ignored.

Copilot uses AI. Check for mistakes.
@wintercms wintercms deleted a comment from Copilot AI Sep 3, 2025
@github-actions
Copy link

github-actions bot commented Nov 3, 2025

This pull request will be closed and archived in 3 days, as there has been no activity in the last 60 days.
If this is still being worked on, please respond and we will re-open this pull request.
If this pull request is critical to your business, consider joining the Premium Support Program where a Service Level Agreement is offered.

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