Skip to content

Commit

Permalink
paths when not in laravel application
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardokum committed Nov 28, 2023
1 parent 70ae287 commit b659338
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
13 changes: 13 additions & 0 deletions src/Listeners/SwiftEmbedImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,19 @@ private function embed(Embedder $embedder, $src)
return $embedder->fromUrl($src);
}

$appPath = method_exists(app(), 'path') ? app_path($src) : null;
$publicPath = app()->resolved('path.public') ? public_path($src) : null;
$storagePath = app()->resolved('path.storage') ? storage_path($src) : null;
if (file_exists($src)) {
return $embedder->fromPath($src);
} elseif ($publicPath && file_exists($publicPath)) { // Try to guess where the file is at that priority level
return $embedder->fromPath($publicPath);
} elseif ($appPath && file_exists($appPath)) {
return $embedder->fromPath($appPath);
} elseif ($storagePath && file_exists($storagePath)) {
return $embedder->fromPath($storagePath);
}

return $src;
}
}
13 changes: 6 additions & 7 deletions src/Listeners/SymfonyEmbedImages.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,16 @@ private function embed(Embedder $embedder, $src)
return $embedder->fromUrl($src);
}

// Path embedding
$publicPath = public_path($src);
$appPath = app_path($src);
$storagePath = storage_path($src);
$appPath = method_exists(app(), 'path') ? app_path($src) : null;
$publicPath = app()->resolved('path.public') ? public_path($src) : null;
$storagePath = app()->resolved('path.storage') ? storage_path($src) : null;
if (file_exists($src)) {
return $embedder->fromPath($src);
} elseif (file_exists($publicPath)) { // Try to guess where the file is at that priority level
} elseif ($publicPath && file_exists($publicPath)) { // Try to guess where the file is at that priority level
return $embedder->fromPath($publicPath);
} elseif (file_exists($appPath)) {
} elseif ($appPath && file_exists($appPath)) {
return $embedder->fromPath($appPath);
} elseif (file_exists($storagePath)) {
} elseif ($storagePath && file_exists($storagePath)) {
return $embedder->fromPath($storagePath);
}

Expand Down

0 comments on commit b659338

Please sign in to comment.