c33s/parameter-objects-bundle
ParameterBag or Container for non-environment-specific parameters, promoting separation of concerns between runtime configs (e.g., parameters.yaml) and domain logic.DATABASE_URL). Risk of YAGNI violation if not justified by scale.PaymentGatewayConfig) or infrastructure (e.g., CacheSettings)?autowire: true for services with PO parameters.phpstan or symfony/var-dumper).['timeout' => 30, 'retries' => 3] → ConnectionConfig PO).int $timeout) with POs in new services.['driver' => 'pdo']) with immutable POs.services.yaml for scalar/array params).parameter('app.some_config') → new AppConfig()).%env(int)% in PO constructors for runtime overrides.ContainerInterface directly may need updates to accept POs.config: YAML with POs where applicable.| Phase | Task | Tools/Artifacts |
|---|---|---|
| Discovery | Map parameter usage in services. | phpstan, symfony/var-dumper |
| PO Design | Define PO interfaces/classes (e.g., FeatureFlagConfig). |
Custom DTOs, PHP 8.2 records |
| Refactor | Update service constructors to use POs. | IDE refactoring, tests |
| Override | Configure env var → PO mapping (e.g., %env(int)% in PO ctor). |
.env, services.yaml |
| Validation | Add runtime validation (e.g., assert($timeout > 0)). |
Symfony Validator, PHP attributes |
| Testing | Update tests to inject POs instead of scalars/arrays. | PHPUnit, Pest |
S3BucketConfig) clarify purpose vs. magic strings.$config->timeout).%env(int)% in constructor).ParameterObjectCompilerPass to auto-generate POs from env vars.AppConfig::DEFAULT).ParameterBag).| Risk | Mitigation Strategy | Example |
|---|---|---|
| Invalid Configs | Runtime validation in PO constructor. | if ($this->timeout <= 0) throw new \InvalidArgumentException(); |
| Circular Dependencies | Avoid PO → Service → PO injection loops. | Use interface segregation. |
| Env Var Mismatches | Explicit mapping in PO constructor. | $this->timeout = (int)$timeoutEnvVar |
| Legacy Code Breaks | Gradual migration with decorators. | Wrap old service with PO-aware adapter. |
| Testing Gaps | Mock POs in unit tests. | createMock(S3Config::class) |
*Config, *Settings).Recommendation: Proceed with pilot adoption in a high-parameter-density module (e.g., payment processing) to validate benefits before full rollout. Pair with PHPStan and autowiring checks to enforce consistency.
How can I help you explore Laravel packages today?