Repository navigation
Open
Labels
Milestone
Description
Summary
Add getBool() and getInt() to Config and use them in the framework instead of the scattered filter_var(..., FILTER_VALIDATE_BOOLEAN) and (int) conversions. Depends on #615.
Why
The framework converts config values by itself in about ten places, because a config file stores whatever env() returned, and env() returns text. This cannot simply be dropped: 'debug' => env('DEBUG', true) stores the string 'true' or 'false' whenever .env has a DEBUG line, which is how every project created from the starter project works. So the conversion stays at the read, in one place, until a major version can require real types.
Where it happens today
filter_var(..., FILTER_VALIDATE_BOOLEAN):is_debug_mode()andDebugger(app.debug),MailerTrait(mailer.mail_trap),ViewCache(resource_cache,view_cache.minify),AuthTrait(two_fa), LangRemoteAdapterTrait(cache.enabled,use_source_catalog), and thetwo_facheck in the DemoApi and DemoWebAuthControllertemplates.(int)on a config value:logging.message.limit,mailer.transport_log_limit,view_cache.ttl,lang.url_segment, the cache adapters'port, and the remember-me lifetime.- No conversion at all: the SMTP
port, thettlof the cache and rate limiter adapters, and theenabledflag inModuleLoader((bool) "false"is true).
Proposed change
ConfigInterfaceandConfiggetgetBool(string $key, bool $default = false): boolandgetInt(string $key, int $default = 0): int, with the same rules as theEnvironmentreaders (Add getBool() and getInt() to Environment, with env_bool() and env_int() helpers #615). The rules should live in one place, not be copied.- Replace the reads above with them. Some of those values come from an adapter's params array and not from a config key; decide for each whether to read the key through
Configor to keep a local conversion. - Behavior stays the same for booleans. For integers, text that is not a whole number now throws instead of becoming
0; call that out in the changelog.
Out of scope
- Trusting the config types and removing the safety net. That breaks every project whose config still says
env('DEBUG', true), so it belongs to 4.0.0.
Breaking changes
- None for valid values. An invalid integer in config now throws instead of becoming
0.
Acceptance criteria
- no
filter_var(..., FILTER_VALIDATE_BOOLEAN)and no(int)of a config value is left insrc, or each one that stays has a reason - tests cover both methods, and the places changed keep their existing tests green
composer test,composer cs:check,composer phpstanandcomposer rector:checkpass on every PHP version in the CI matrix- the changelog lists the change
Activity