Skip to content

Commit

Permalink
Use CDN locally
Browse files Browse the repository at this point in the history
  • Loading branch information
timkelty committed Feb 14, 2024
1 parent 6350f50 commit 15071a2
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use craft\fs\Temp;
use craft\helpers\App;
use craft\imagetransforms\FallbackTransformer;
use craft\imagetransforms\ImageTransformer as CraftImageTransformerAlias;
use craft\imagetransforms\ImageTransformer as CraftImageTransformer;
use craft\log\Dispatcher;
use craft\log\MonologTarget;
use craft\services\Elements;
Expand Down Expand Up @@ -79,6 +79,24 @@ public function bootstrap($app): void
if (Helper::isCraftCloud()) {
$this->bootstrapCloud($app);
}

if ($this->getConfig()->getUseAssetCdn()) {
$app->getImages()->supportedImageFormats = ImageTransformer::SUPPORTED_IMAGE_FORMATS;

/**
* Currently this is the only reasonable way to change the default transformer
*/
Craft::$container->set(
CraftImageTransformer::class,
ImageTransformer::class,
);

// TODO: this is to ensure PHP never transforms. Test this.
Craft::$container->set(
FallbackTransformer::class,
ImageTransformer::class,
);
}
}

public function getConfig(): Config
Expand Down Expand Up @@ -135,22 +153,6 @@ protected function bootstrapCloud(ConsoleApplication|WebApplication $app): void
})
->all();

$app->getImages()->supportedImageFormats = ImageTransformer::SUPPORTED_IMAGE_FORMATS;

/**
* Currently this is the only reasonable way to change the default transformer
*/
Craft::$container->set(
CraftImageTransformerAlias::class,
ImageTransformer::class,
);

// TODO: this is to ensure PHP never transforms. Test this.
Craft::$container->set(
FallbackTransformer::class,
ImageTransformer::class,
);

Craft::$container->set(
Temp::class,
TmpFs::class,
Expand Down

0 comments on commit 15071a2

Please sign in to comment.