Add typed getters to Config - #928
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.phpthat 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors how configuration values are accessed throughout the codebase to use type-specific getter methods (such as
getBool,getString,getInt, andgetArray) instead of the genericgetmethod. 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
getcalls 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.phpto use type-specific config accessors, ensuring dependencies receive correctly typed configuration values. (formwork/src/Cms/App.php) [1] [2] [3]File and Metadata Handling
getStringandgetArrayfor 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
formwork/src/Commands/BackupCommand.php,formwork/src/Commands/CacheCommand.php,formwork/src/Commands/UpdatesCommand.php) [1] [2] [3] [4] [5] [6]General Improvements
UnexpectedValueExceptioninConfig.phpto support stricter error handling. (formwork/src/Config/Config.php)These changes collectively enhance the robustness and maintainability of configuration management throughout the codebase.