Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
.php-cs-fixer.cache

/assets/*
/backup/*
/cache/*
/logs/*
Expand Down
6 changes: 5 additions & 1 deletion formwork/config/routes/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
'action' => 'Formwork\Controllers\PageController@load',
],
'assets' => [
'path' => '/assets/{id}/{name}/',
/** @todo require the type param in Formwork >= 3.0.0 */
'path' => '/assets/{type}?/{id}/{name}/',
'where' => [
'type' => ['images', null],
],
'action' => 'Formwork\Controllers\AssetsController@asset',
],
'assets.template' => [
Expand Down
2 changes: 1 addition & 1 deletion formwork/config/system.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ images:
webpQuality: 85
avifQuality: 70
gifColors: 256
processPath: ${%ROOT_PATH%}/cache/images
processPath: ${%ROOT_PATH%}/assets/images
preserveColorProfile: true
preserveExifData: true
clearCacheByDefault: false
Expand Down
6 changes: 6 additions & 0 deletions formwork/src/Controllers/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Formwork\Http\FileResponse;
use Formwork\Http\Response;
use Formwork\Http\ResponseStatus;
use Formwork\Router\RouteParams;
use Formwork\Utils\FileSystem;
use Formwork\Utils\Path;
Expand All @@ -15,6 +16,11 @@ final class AssetsController extends AbstractController
*/
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);
Copy link

Copilot AI Feb 15, 2026

Choose a reason for hiding this comment

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

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.

Suggested change
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);

Copilot uses AI. Check for mistakes.
return $this->redirect($this->router->rewrite(['type' => 'images']), ResponseStatus::MovedPermanently);
}

$path = FileSystem::joinPaths($this->config->get('system.images.processPath'), $routeParams->get('id'), $routeParams->get('name'));

if (FileSystem::isFile($path, assertExists: false)) {
Expand Down
2 changes: 1 addition & 1 deletion formwork/src/Files/FileUriGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function generate(File $file): string
if (Str::startsWith($path, FileSystem::normalizePath($this->config->get('system.images.processPath')))) {
$id = basename(dirname($path));
$name = basename($path);
$uriPath = $this->router->generate('assets', compact('id', 'name'));
$uriPath = $this->router->generate('assets', ['type' => 'images', 'id' => $id, 'name' => $name]);
return $this->site->uri($uriPath, includeLanguage: false);
}

Expand Down