Skip to content

Add typed getters to Config - #928

Merged
giuscris merged 2 commits into
2.xfrom
feature/config-typed-getters
Aug 18, 2026
Merged

Add typed getters to Config#928
giuscris merged 2 commits into
2.xfrom
feature/config-typed-getters

Conversation

@giuscris

@giuscris giuscris commented Aug 18, 2026

Copy link
Copy Markdown
Member

This pull request refactors how configuration values are accessed throughout the codebase to use type-specific getter methods (such as getBool, getString, getInt, and getArray) instead of the generic get method. This change improves type safety, clarity, and reduces the risk of runtime errors due to unexpected value types. The update touches many files across the application, especially in routing, field processing, view rendering, file handling, and command-line utilities.

Configuration Access Refactoring

  • Replaced generic get calls with type-specific methods (getBool, getString, getInt, getArray) in route filters, view methods, and field definitions for more robust type handling. (formwork/config/routes/routes.php, formwork/config/views/methods.php, formwork/fields/date.php, formwork/fields/markdown.php, formwork/fields/upload.php) [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

  • Updated service container definitions and route loading in App.php to use type-specific config accessors, ensuring dependencies receive correctly typed configuration values. (formwork/src/Cms/App.php) [1] [2] [3]

File and Metadata Handling

  • Changed file handling logic to use getString and getArray for paths and allowed extensions, preventing issues when non-string or non-array values are returned from configuration. (formwork/src/Cms/Site.php) [1] [2] [3] [4]

CLI Command Improvements

  • Refactored backup, cache, and update commands to use type-specific config accessors, improving reliability and maintainability of command-line operations. (formwork/src/Commands/BackupCommand.php, formwork/src/Commands/CacheCommand.php, formwork/src/Commands/UpdatesCommand.php) [1] [2] [3] [4] [5] [6]

General Improvements

  • Added missing import for UnexpectedValueException in Config.php to support stricter error handling. (formwork/src/Config/Config.php)

These changes collectively enhance the robustness and maintainability of configuration management throughout the codebase.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces typed getter methods on Formwork\Config\Config (e.g., getString(), getBool(), getInt(), getArray()) and updates call sites across the Panel and core runtime to use them, making config access stricter and more explicit.

Changes:

  • Added typed getters to formwork/src/Config/Config.php that validate config value types and throw on mismatch.
  • Migrated many config reads from get() / getMultiple() to typed getters for clearer intent and stronger runtime guarantees.
  • Updated various loaders, controllers, and view templates to use typed getters and provide defaults where needed.

Reviewed changes

Copilot reviewed 59 out of 59 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
panel/views/fields/upload.php Uses getArray() for allowed extensions when building the accept attribute.
panel/views/errors/error.php Uses typed getters for debug editor URI and context lines.
panel/config/routes/routes.php Uses getString() for panel assets path in route action.
panel/config/app.php Uses typed getters for date input configuration values.
formwork/views/errors/partials/debug.php Uses typed getters for debug editor URI and context lines.
formwork/src/Users/User.php Uses getString() for user accounts/images path config.
formwork/src/Translations/Translations.php Uses getString() for translations fallback code.
formwork/src/Templates/TemplateFactory.php Uses getString() for templates path.
formwork/src/Services/Loaders/UsersServiceLoader.php Uses getString() for users roles/accounts paths.
formwork/src/Services/Loaders/TranslationsServiceLoader.php Uses getString() for translations system/site paths.
formwork/src/Services/Loaders/TemplatesServiceLoader.php Uses getString() for templates path.
formwork/src/Services/Loaders/SiteServiceLoader.php Uses getArray('site') and getString() for content path.
formwork/src/Services/Loaders/SchemesServiceLoader.php Uses getString() for schemes paths and dynamic vars file.
formwork/src/Services/Loaders/PluginsServiceLoader.php Uses typed getters for plugin enable flag and plugins path.
formwork/src/Services/Loaders/PanelServiceLoader.php Uses typed getters for panel/auth/update/session/view/scheme/translation config.
formwork/src/Services/Loaders/LoggerServiceLoader.php Uses getArray() for log handler configs.
formwork/src/Services/Loaders/ConfigServiceLoader.php Uses typed getters when applying timezone and session configuration.
formwork/src/Services/Loaders/AuthenticationServiceLoader.php Uses typed getters for rate limiter configuration.
formwork/src/Services/Loaders/AssetsServiceLoader.php Uses getString() for template assets path.
formwork/src/Plugins/Plugins.php Uses getBool() for per-plugin enabled flag when initializing plugins.
formwork/src/Plugins/Plugin.php Uses getBool() for plugin enabled flag with default.
formwork/src/Plugins/Controllers/AssetsController.php Uses getString() for plugins path when resolving asset files.
formwork/src/Parsers/Extensions/CommonMark/ImageAltProcessor.php Adds phpdoc typing hints for configuration values used during image alt processing.
formwork/src/Panel/Panel.php Uses typed getters for panel path/root/config files and defaults.
formwork/src/Panel/Modals/ModalFactory.php Uses getString() for panel modals path.
formwork/src/Panel/Controllers/UsersController.php Uses typed getters for users images path and image size.
formwork/src/Panel/Controllers/UpdatesController.php Uses getBool()/getArray() for updates and backup behavior.
formwork/src/Panel/Controllers/ToolsController.php Uses getArray() for backup configuration and getBool() for debug enabled.
formwork/src/Panel/Controllers/PluginsController.php Uses getArray() when reading/updating plugin options.
formwork/src/Panel/Controllers/PagesController.php Uses getString() for datetime format when formatting timestamps.
formwork/src/Panel/Controllers/OptionsController.php Uses getArray() for loading system/site option defaults/overrides.
formwork/src/Panel/Controllers/FilesController.php Uses typed getters for formats, paths, and metadata extension.
formwork/src/Panel/Controllers/ErrorsController.php Uses getBool() for debug-enabled branching.
formwork/src/Panel/Controllers/CacheController.php Uses typed getters for images cache defaults and process path.
formwork/src/Panel/Controllers/BackupController.php Uses typed getters for backup config, formats, and max files.
formwork/src/Panel/Controllers/AuthenticationController.php Uses getString() for logout redirect config.
formwork/src/Panel/Controllers/AssetsController.php Uses getString() for panel assets path.
formwork/src/Pages/Traits/PageStatus.php Replaces getMultiple() with explicit getString() calls for date formats.
formwork/src/Pages/Page.php Uses typed getters for extensions, metadata extension, allowed extensions, and date formats.
formwork/src/Images/ImageFactory.php Uses getArray() for image default options.
formwork/src/Files/Services/FileUploader.php Uses typed getters for allowed extensions/destinations and uploads processing flag.
formwork/src/Files/FileUriGenerator.php Uses typed getters for various configured filesystem roots.
formwork/src/Files/FileFactory.php Uses getString() for metadata extension.
formwork/src/Fields/FieldFactory.php Uses getString() for fields config path.
formwork/src/Controllers/PageController.php Uses typed getters for statistics/cache/panel/page index config.
formwork/src/Controllers/FilesController.php Uses getString() for site files path.
formwork/src/Controllers/ErrorsController.php Uses getBool() for debug-enabled branching.
formwork/src/Controllers/AssetsController.php Uses getString() for image process path and templates path.
formwork/src/Config/Config.php Adds typed getters (getString/getBool/getInt/getFloat/getArray) with strict type validation.
formwork/src/Commands/UpdatesCommand.php Uses typed getters for cache enabled and updates/backup arrays.
formwork/src/Commands/CacheCommand.php Uses getString() for cache-related paths.
formwork/src/Commands/BackupCommand.php Uses getArray() for backup configuration.
formwork/src/Cms/Site.php Uses typed getters for charset, generator flag, index/error page routes, and file settings.
formwork/src/Cms/App.php Uses typed getters for views/stats/cache/routes/panel-related config reads.
formwork/fields/upload.php Uses getArray() for allowed extensions in upload field logic.
formwork/fields/markdown.php Uses typed getters for markdown parser options.
formwork/fields/date.php Replaces getMultiple() with explicit getString() for date formats.
formwork/config/views/methods.php Uses typed getters for markdown/date/datetime view helpers.
formwork/config/routes/routes.php Uses typed getters for panel gating in request filters.

馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread formwork/src/Plugins/Plugins.php Outdated
@giuscris
giuscris merged commit f2e9e02 into 2.x Aug 18, 2026
1 check passed
@giuscris
giuscris deleted the feature/config-typed-getters branch August 18, 2026 12:11
@giuscris giuscris added the core label Aug 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants