chillerlan/php-settings-container
A lightweight PHP settings container that decouples configuration logic from your application. It is not a DI container, offering typed settings objects, property hooks for PHP before 8.4, and straightforward access, merging, and serialization.
Architecture fit. chillerlan/php-settings-container is a deliberately small, single-purpose library: a typed settings/options object that composes behavior via traits, exposes magic getters/setters (with set_/get_ convention and PHP 8.4 property-hook awareness), and serializes to/from arrays, JSON, and PHP serialization. It explicitly disclaims being a DI container. For Laravel, the closest architectural analogues are untyped config() arrays, hand-rolled DTOs, or spatie/laravel-data. The fit is best inside a package that needs a pluggable options bag (the way the maintainer's own libraries, e.g. php-qrcode, use it), and weakest as a general DTO layer for application code where PHP readonly classes or framework-native config already suffice. Verdict: narrow, legitimate fit; not a broad platform dependency.
Integration feasibility. Low friction. Composer-only, no Laravel service provider, no config publishing, MIT license. The real gate is the PHP ^8.4 floor introduced in 4.0.0 (3.x supported earlier PHP). Laravel 11/12 can run on 8.4, but many production stacks are still on 8.2/8.3, so adoption is contingent on the platform upgrade roadmap rather than on this package.
Technical risk.
toArray() to route through the magic getter; 3.3.0 adjusted get/set behavior for property hooks and added hasSetHook()/hasGetHook(). Consumers must pin and test, not float.protected, but magic __set still mutates post-construction. Not a guarantee of immutability.null unless #[ThrowOnInvalidProperty(true)] is set — an easy source of misconfiguration bugs.rules-magic-access.neon PHPStan ruleset to avoid false positives.Key questions for vendor/owner decision.
^8.4, and does the Laravel version in scope?readonly classes are a better tool) or just typed, serializable settings?ThrowOnInvalidProperty convention as house standards?Stack fit. Composer 2 + Laravel 11/12 on PHP 8.4+. It slots in as a leaf dependency: an internal package's options class, a config value object for CLI/batch jobs, or a serializable settings boundary consumed by JSON/array at the edges. It is not a substitute for the Laravel service container, the config repository, or Eloquent casts — plan for coexistence, not replacement.
Migration path. Do not attempt a wholesale DTO migration. Pilot in one bounded internal package or module where options are currently passed as associative arrays. Define a SettingsContainerAbstract subclass, compose 1–2 traits, and observe ergonomics, PHPStan noise, and serialization behavior in a single call path. Expand only if the pilot demonstrates value over readonly classes.
Compatibility.
set_/get_ method also exists, only the hook is called — ensure teams don't define both accidentally.JsonSerializable and Serializable; JSON encode/decode routes through toArrayFromIterable, while serialize/unserialize bypass magic access and hooks. That asymmetry matters for caching.Sequencing.
#[ThrowOnInvalidProperty(true)].set_/get_ prefixes, serialization guidance).Maintenance. Small code surface, MIT, active releases (latest tagged 2026-03-20 per snapshot). Primary risk is concentration: a single-maintainer project with low external adoption. Mitigation is straightforward — vendor-fork or pin to a tested minor and treat upgrades as deliberate change events.
Support. Community issues only; no SLA. For enterprise use, assign an internal owner for the pilot and a documented upgrade policy. The README and release notes are adequate, but the disclaimer ("either absolutely brilliant or completely stupid") signals a personal-library ethos rather than commercial support posture.
Scaling. Negligible runtime concern — plain PHP objects with magic access; performance is bounded by object count and JSON encode costs at boundaries. This is not a scaling risk.
Failure modes to watch.
toArray()/magic get/set (3.2.0, 3.3.0) affecting JSON output contracts.null on invalid property writes when the throw attribute is omitted.serialize/unserialize and JSON paths affecting cache round-trips.Ramp-up. Low for developers: the API surface is small (toArray, toJSON, fromJSON, fromIterable, trait constructor convention). The learning curve is in the conventions (trait-based options, prefixed magic methods, PHPStan configuration), not the code. Budget half a day of onboarding plus an internal guide; without the PHPStan ruleset, expect developer friction from magic-property diagnostics.
How can I help you explore Laravel packages today?