- How does stillat/proteus differ from Laravel’s built-in config system for dynamic runtime changes?
- Proteus extends Laravel’s config system by allowing runtime modifications to config files (e.g., updating `config/app.php` without restarting the server) while preserving Laravel’s dot-notation syntax. Unlike Laravel’s static `config()` helper, it supports live writes, validation hooks, and custom parsers—useful for feature flags or environment-specific overrides without redeploying.
- Can I use stillat/proteus in a non-Laravel PHP project (e.g., Symfony, Lumen, or standalone scripts)?
- Yes, Proteus is designed as a standalone library. You can initialize it with a config file path and use its API (e.g., `Proteus::set('key', 'value')->write()`) without Laravel dependencies. However, some Laravel-specific features like ConfigServiceProvider integration won’t work unless manually adapted.
- What Laravel versions and PHP requirements does stillat/proteus support?
- Proteus officially supports Laravel 10.x and 11.x (LTS versions) and requires PHP 8.1+. For older Laravel versions (pre-8.0), you may need compatibility shims or custom adapters, but the package prioritizes modern PHP features like typed properties and attributes.
- How do I secure dynamic config writes in production (e.g., prevent arbitrary file overwrites)?
- Proteus doesn’t expose file writes by default, but if you use `Proteus::write()`, restrict access via Laravel middleware (e.g., `can:admin`) or environment checks. Validate input against a schema (e.g., using `validate()`) to block malicious payloads. Avoid exposing the write endpoint publicly.
- Is there a performance impact when using Proteus for large config files (e.g., 100KB+)?
- Proteus parses config files on-demand, which adds minor overhead compared to Laravel’s static `require` approach. For large files, cache the parsed object in memory (e.g., via Laravel’s cache facade) or preload configs during boot. Benchmark against your baseline to assess trade-offs.
- Can I integrate stillat/proteus with a database (e.g., store configs in MySQL/PostgreSQL)?
- Proteus works with files by default, but you can serialize configs to JSON/DB fields using Eloquent or Doctrine. For example, store a config array as JSON in a `configs` table and hydrate it with `Proteus::load(json_decode($record->config, true))`. This adds coupling but enables dynamic DB-backed configs.
- How do I test config validation and fallbacks in CI (e.g., ensure required keys exist)?
- Use Proteus’s `validate()` method with a closure or array schema to enforce rules (e.g., `Proteus::validate(['database.timeout' => 'required|integer'])`). Test edge cases like missing files or invalid data by mocking `Proteus::load()` in PHPUnit. For fallbacks, use `Proteus::get('key', 'default')` and assert expected values.
- What are the alternatives to stillat/proteus for dynamic Laravel configs?
- For Laravel-specific needs, consider `spatie/laravel-config-array` (simpler, file-based) or `vlucas/phpdotenv` (env-focused). For microservices, use Consul or etcd with a custom adapter. Proteus stands out for its runtime editability, validation hooks, and Laravel-native integration, but choose lighter options if you only need static configs.
- How do I migrate from Laravel’s static config to stillat/proteus without breaking existing code?
- Start by replacing `config('key')` with `Proteus::get('key')` in `bootstrap/app.php`. For dynamic configs, add a `/config` API endpoint using `Proteus::write()` with auth. Gradually phase out static files by extending Laravel’s `ConfigRepository` to use Proteus as the backend, ensuring backward compatibility during the transition.
- Does stillat/proteus support environment-specific config overrides (e.g., `.env`-like behavior for config files)?
- Yes, Proteus can merge configs from multiple files (e.g., `config/app.php`, `config/app.local.php`) using its `merge()` method. Combine this with Laravel’s `.env` for a hybrid approach: use `.env` for environment variables and Proteus for structured, runtime-editable configs. Example: `Proteus::load('config/app.php')->merge('config/app.'.$env.'.php')`.