Use assets folder to store cached assets and serve them directly#860
Use assets folder to store cached assets and serve them directly#860
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates Formwork’s cached image asset handling so generated images are written under /assets/images and URLs include an explicit asset type, enabling web servers to serve cached images directly (bypassing PHP) while keeping backward compatibility for legacy asset URLs.
Changes:
- Update the
assetsroute to support an optional{type}segment (currently constrained toimages) and redirect legacy requests missingtype. - Adjust image asset URI generation to always include
type=images. - Move the configured processed image output directory from
cache/imagestoassets/images, and ignore/assets/*in git.
Reviewed changes
Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| formwork/src/Files/FileUriGenerator.php | Ensures generated asset URIs include type=images to match the new route format. |
| formwork/src/Controllers/AssetsController.php | Adds legacy-route deprecation + permanent redirect to the typed asset route. |
| formwork/config/system.yaml | Moves processed image output path to ${%ROOT_PATH%}/assets/images. |
| formwork/config/routes/routes.php | Updates assets route path to include optional {type} and constrains allowed values. |
| .gitignore | Ignores generated /assets/* content in the repository. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public function asset(RouteParams $routeParams): Response | ||
| { | ||
| if (!$routeParams->has('type')) { | ||
| trigger_error('The "assets" route without a "type" parameter is deprecated and will be removed in a future version', E_USER_DEPRECATED); |
There was a problem hiding this comment.
The deprecation warning message doesn’t follow the existing deprecation-message convention in this codebase (most other E_USER_DEPRECATED messages include the version it was deprecated since). Consider updating the message to include the Formwork version when this route format became deprecated so it’s actionable when it appears in logs.
| trigger_error('The "assets" route without a "type" parameter is deprecated and will be removed in a future version', E_USER_DEPRECATED); | |
| trigger_error('The "assets" route without a "type" parameter is deprecated since Formwork 1.x and will be removed in a future version', E_USER_DEPRECATED); |
This pull request closes #859 by introducing changes to improve asset routing and handling, particularly for image assets. Now the generated image assets are stored in the /assets folder, allowing direct serving without php processing.
The main focus is on making the asset type explicit in routes, updating image processing paths, and preparing for future deprecations. Below are the most important changes grouped by theme:
Routing and asset handling improvements:
assetsroute inroutes.phpto include an optionaltypeparameter, defaulting toimages, and added awhereclause to restrict valid types. This makes asset type explicit and prepares for future versions where the parameter will be required.AssetsController::assetto trigger a deprecation warning if thetypeparameter is missing and redirect requests to includetype=images. This ensures backward compatibility while encouraging use of the new route format.FileUriGenerator::generateto always include thetype=imagesparameter when generating asset URIs, ensuring consistency with the updated route structure.Configuration updates:
processPathfor images insystem.yamlfromcache/imagestoassets/images, aligning the configuration with the new asset management approach.