axdlee/laravel-config-writer
Write safely to Laravel config PHP files (Laravel 5.3+), updating nested keys while preserving formatting, comments, and advanced settings. Supports strings, ints, booleans, and single-level arrays. Includes Laravel service provider and standalone Rewrite class.
Pros:
Config component, ensuring seamless integration with Laravel’s ecosystem (5.3+).Config system is read-only, making runtime configuration updates impossible without manual file edits or third-party solutions.nested.config.item), aligning with Laravel’s conventions and reducing boilerplate for nested configurations.Cons:
strings, integers, booleans, and single-dimension arrays. Complex nested arrays, objects, or custom PHP types (e.g., Carbon instances) require manual serialization/deserialization.app.debug remains a boolean).Config repository or file structure (e.g., config/cache).config:clear) or integration with Laravel’s ConfigRepository events.| Risk Area | Severity | Mitigation Strategy |
|---|---|---|
| Config cache staleness | High | Implement post-write cache invalidation or use config:clear in a queue job. |
| File corruption | Medium | Wrap writes in transactions (e.g., lock files) or use a backup strategy. |
| Type safety | Medium | Add validation layers (e.g., cast writes to expected types before saving). |
| Laravel version drift | Medium | Test against target Laravel versions; consider forking for LTS support. |
| Permission issues | Low | Ensure the web server user has write access to config/ (risky; prefer restricted paths). |
| Testing complexity | Low | Mock file I/O for unit tests; use Docker for integration tests. |
Why write configs at runtime?
Cache strategy:
config:cache? Will writes trigger cache invalidation, or will you live with stale configs?Security:
Alternatives evaluated:
Error handling:
Performance:
Future-proofing:
Best for:
Poor fit:
Assessment Phase:
Pilot Integration:
app.debug, services.log.level).ConfigWriter::write()) for easier testing and rollback.Core Integration:
config/app.php:
Axdlee\Config\ConfigServiceProvider::class,
config:clear).app.timezone is a string).Cache Handling:
Artisan::call('config:clear')).Security Hardening:
config/dynamic/*.php).ConfigRepository in Laravel 8).bootstrap/cache/config.php).Rewrite class can be used standalone, but loses Laravel-specific features (e.g., cache integration).Phase 1: Read-Only Validation
return []; wrappers or complex structures).Phase 2: Basic Writes
Phase 3: Array Support
services.providers).nested.array[0]) fail gracefully or are handled via serialization.Phase 4: Production Readiness
Phase 5: Scaling
How can I help you explore Laravel packages today?