Skip to content

Commit

Permalink
Add file exist check and fallback to http (#13)
Browse files Browse the repository at this point in the history
* Add file exist check and fallback to http

* Also check file if force is added
  • Loading branch information
alexander-schranz authored Feb 20, 2020
1 parent cecac30 commit 519b359
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Twig/LocalAssetTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,17 @@ public function getFilters()
*/
public function getLocalAsset($assetUrl, $force = false)
{
$prefix = 'file://' . $this->publicDirectory;
$assetUrl = '/' . ltrim($assetUrl, '/');
$filePath = $this->publicDirectory . $assetUrl;
$prefix = 'file://' . $this->publicDirectory;

if ($force) {
if ($force && file_exists($filePath)) {
return $prefix . $assetUrl;
}

$request = $this->requestStack->getCurrentRequest();

if ($request && 'html' === $request->getRequestFormat()) {
if ($request && ('html' === $request->getRequestFormat() || !file_exists($filePath))) {
$prefix = $request->getSchemeAndHttpHost();
}

Expand Down

0 comments on commit 519b359

Please sign in to comment.