Skip to content

Correctly ensure platform requirements in the codebase - #922

Merged
giuscris merged 2 commits into
2.xfrom
feature/ensure-platform-requirements
Aug 12, 2026
Merged

Correctly ensure platform requirements in the codebase#922
giuscris merged 2 commits into
2.xfrom
feature/ensure-platform-requirements

Conversation

@giuscris

Copy link
Copy Markdown
Member

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:

  • Updated composer.json to require all necessary PHP extensions, including exif, filter, libxml, session, tokenizer, and zlib, ensuring Composer will block installation if any are missing.
  • Expanded the "Requirements" section in README.md to list all required PHP extensions and clarified installation/build instructions. [1] [2] [3] [4]

Runtime Extension Checks:

  • Added explicit runtime checks for required extensions (e.g., zip, zlib, dom, exif, session, tokenizer, fileinfo) in constructors and critical methods throughout the codebase, throwing clear RuntimeExceptions if missing. This affects classes such as Backupper, 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:

  • Improved error handling by ensuring that features relying on optional extensions (such as gzip decoding, image profile encoding/decoding, PHP code highlighting, and DOM parsing) fail fast and with descriptive errors if the extension is not available. [1] [2] [3] [4] [5]

These changes collectively ensure that missing PHP extensions are detected early, both at install time and runtime, preventing obscure failures and improving maintainability.

@giuscris
giuscris requested a lite review from Copilot August 12, 2026 09:30
@giuscris giuscris self-assigned this Aug 12, 2026
@giuscris giuscris added the enhancement New feature or request label Aug 12, 2026

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 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 synced composer.lock) and documented them in README.md.
  • Added runtime extension_loaded() checks to multiple components that depend on zip, zlib, dom, exif, session, and tokenizer.
  • 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: gzip but zlib isn’t available, the code throws “Unsupported Content-Encoding "gzip"…”, which is misleading (gzip is supported; the missing dependency is zlib). 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.

Comment thread README.md Outdated
Comment thread formwork/src/Utils/MimeType.php
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@giuscris
giuscris merged commit cf31740 into 2.x Aug 12, 2026
1 check passed
@giuscris
giuscris deleted the feature/ensure-platform-requirements branch August 12, 2026 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants