Skip to content

Add getBool() and getInt() to Config and use them instead of filter_var and (int) in the framework #616

Open

Description

@armanist

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() and Debugger (app.debug), MailerTrait (mailer.mail_trap), ViewCache (resource_cache, view_cache.minify), AuthTrait (two_fa), Lang RemoteAdapterTrait (cache.enabled, use_source_catalog), and the two_fa check in the DemoApi and DemoWeb AuthController templates.
  • (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, the ttl of the cache and rate limiter adapters, and the enabled flag in ModuleLoader ((bool) "false" is true).

Proposed change

  • ConfigInterface and Config get getBool(string $key, bool $default = false): bool and getInt(string $key, int $default = 0): int, with the same rules as the Environment readers (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 Config or 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 in src, 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 phpstan and composer rector:check pass on every PHP version in the CI matrix
  • the changelog lists the change

Activity

  1. added this to the 3.1.2 milestone on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions