Correctly ensure platform requirements in the codebase - #922
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request tightens Formwork’s platform requirements by declaring required PHP extensions in Composer, documenting them in the README, and adding runtime guards so extension-dependent code fails with clearer errors.
Changes:
- Expanded required PHP extensions in
composer.json(and syncedcomposer.lock) and documented them inREADME.md. - Added runtime
extension_loaded()checks to multiple components that depend onzip,zlib,dom,exif,session, andtokenizer. - Adjusted HTTP gzip decoding behavior and added extension checks around tokenizer usage and PNG profile compression.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Updates documented PHP extension requirements and adds spacing/formatting adjustments. |
| formwork/src/Utils/MimeType.php | Adds an extension check in MimeType::fromFile() before MIME detection. |
| formwork/src/Updater/Updater.php | Adds a zip extension guard to prevent updater use without ext-zip. |
| formwork/src/Sanitizer/Parser/PhpDomParser.php | Adds a dom extension guard before using DOMDocument. |
| formwork/src/Sanitizer/Parser/Html5Parser.php | Adds a dom extension guard before using HTML5/DOM parsing. |
| formwork/src/Sanitizer/DomSanitizer.php | Adds a dom extension guard in the sanitizer constructor. |
| formwork/src/Images/Handler/PngHandler.php | Adds zlib guards around gzcompress/gzuncompress usage. |
| formwork/src/Images/Exif/ExifReader.php | Adds an exif extension guard in the EXIF reader constructor. |
| formwork/src/Images/Decoder/SvgDecoder.php | Adds a dom extension guard before SVG XML parsing. |
| formwork/src/Http/Session/Session.php | Improves the error message when ext-session is missing. |
| formwork/src/Http/Client.php | Changes gzip decoding behavior and error handling for Content-Encoding. |
| formwork/src/Debug/CodeDumper.php | Adds a tokenizer extension guard before PHP tokenization/highlighting. |
| formwork/src/Backup/Backupper.php | Adds a zip extension guard to prevent backups without ext-zip. |
| composer.json | Declares additional required PHP extensions via ext-* constraints. |
| composer.lock | Updates platform requirements hash and recorded ext-* requirements. |
Suppressed comments (1)
formwork/src/Http/Client.php:97
- When the response is
Content-Encoding: gzipbutzlibisn’t available, the code throws “Unsupported Content-Encoding "gzip"…”, which is misleading (gzip is supported; the missing dependency iszlib). Consider explicitly detecting this case and throwing a targeted error message.
if ($encoding === 'gzip' && extension_loaded('zlib')) {
$content = gzdecode($content);
if ($content === false) {
throw new RuntimeException(sprintf('Cannot decode gzipped contents from "%s"', $uri));
}
} elseif ($encoding !== null) {
throw new RuntimeException(sprintf('Unsupported Content-Encoding "%s" from "%s"', $encoding, $uri));
}
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
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 strengthens the handling of required PHP extensions across the codebase by explicitly checking for their presence and providing clear error messages if missing. It also updates documentation and dependency declarations to accurately reflect all required extensions. These changes improve reliability, developer experience, and clarity for both users and contributors.
Dependency and Documentation Updates:
composer.jsonto require all necessary PHP extensions, includingexif,filter,libxml,session,tokenizer, andzlib, ensuring Composer will block installation if any are missing.README.mdto list all required PHP extensions and clarified installation/build instructions. [1] [2] [3] [4]Runtime Extension Checks:
zip,zlib,dom,exif,session,tokenizer,fileinfo) in constructors and critical methods throughout the codebase, throwing clearRuntimeExceptions if missing. This affects classes such asBackupper,Updater,SvgDecoder,ExifReader,Session,DomSanitizer,Html5Parser,PhpDomParser, and methods in image and HTTP handlers. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]Code Robustness:
These changes collectively ensure that missing PHP extensions are detected early, both at install time and runtime, preventing obscure failures and improving maintainability.