Skip to content

Commit

Permalink
Rewrite to comply to coding standards
Browse files Browse the repository at this point in the history
  • Loading branch information
jissereitsma committed Dec 11, 2024
1 parent 683c815 commit d89d854
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Util/UrlConvertor.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\Exception\FileSystemException;
use Magento\Framework\Exception\NoSuchEntityException;
use Magento\Framework\Filesystem\DirectoryList;
use Magento\Framework\Filesystem\Driver\File as FileDriver;
use Magento\Framework\UrlInterface;
use Magento\Framework\View\Asset\File\NotFoundException;
use Magento\Store\Model\Store;
Expand All @@ -30,6 +31,7 @@ class UrlConvertor
* @var Escaper
*/
private $escaper;
private FileDriver $fileDriver;

/**
* @param StoreManagerInterface $storeManager
Expand All @@ -39,11 +41,13 @@ class UrlConvertor
public function __construct(
StoreManagerInterface $storeManager,
DirectoryList $directoryList,
Escaper $escaper
Escaper $escaper,
FileDriver $fileDriver
) {
$this->storeManager = $storeManager;
$this->directoryList = $directoryList;
$this->escaper = $escaper;
$this->fileDriver = $fileDriver;
}

/**
Expand Down Expand Up @@ -87,7 +91,7 @@ public function getUrlFromFilename(string $filename): string
{
try {
$mediaFolder = $this->getMediaFolder();
$realMediaFolder = realpath($mediaFolder);
$realMediaFolder = $this->fileDriver->getRealPath($mediaFolder);
if (str_contains($filename, $realMediaFolder)) {
return str_replace($mediaFolder.'/', $this->getMediaUrl(), $filename);
}
Expand All @@ -97,7 +101,7 @@ public function getUrlFromFilename(string $filename): string

try {
$staticFolder = $this->getStaticFolder();
$realStaticFolder = realpath($staticFolder);
$realStaticFolder = $this->fileDriver->getRealPath($staticFolder);
if (str_contains($filename, $realStaticFolder)) {
return str_replace($this->getStaticFolder().'/', $this->getStaticUrl(), $filename);
}
Expand All @@ -106,7 +110,7 @@ public function getUrlFromFilename(string $filename): string
}

$baseFolder = $this->getBaseFolder();
$realBaseFolder = realpath($baseFolder);
$realBaseFolder = $this->fileDriver->getRealPath($baseFolder);
if (str_contains($filename, $realBaseFolder)) {
return str_replace($this->getBaseFolder().'/', $this->getBaseUrl(), $filename);
}
Expand Down

0 comments on commit d89d854

Please sign in to comment.