-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: decorate sw_encode_url to support imgproxy, update codestyle (#142
- Loading branch information
Showing
9 changed files
with
59 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Storefront/Framework/Twig/Extension/UrlEncodingTwigFilter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Frosh\ThumbnailProcessor\Storefront\Framework\Twig\Extension; | ||
|
||
use Shopware\Storefront\Framework\Twig\Extension\UrlEncodingTwigFilter as ShopwareUrlEncodingTwigFilter; | ||
|
||
class UrlEncodingTwigFilter extends ShopwareUrlEncodingTwigFilter | ||
{ | ||
public function encodeUrl(?string $mediaUrl): ?string | ||
{ | ||
$mediaUrl = parent::encodeUrl($mediaUrl); | ||
|
||
if ($mediaUrl === null) { | ||
return null; | ||
} | ||
|
||
// this adds support for imgproxy with the procession options coming with version 3.0 | ||
return \str_replace('%3A', ':', $mediaUrl); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
tests/unit/Storefront/Framework/Twig/Extension/UrlEncodingTwigFilterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Frosh\ThumbnailProcessor\Tests\Unit\Storefront\Framework\Twig\Extension; | ||
|
||
use Frosh\ThumbnailProcessor\Storefront\Framework\Twig\Extension\UrlEncodingTwigFilter; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class UrlEncodingTwigFilterTest extends TestCase | ||
{ | ||
public function testEncodeUrl(): void | ||
{ | ||
$urlEncodingTwigFilter = new UrlEncodingTwigFilter(); | ||
$result = $urlEncodingTwigFilter->encodeUrl('https://example.com/w:1/image.jpg'); | ||
static::assertSame('https://example.com/w:1/image.jpg', $result); | ||
} | ||
|
||
public function testEncodeUrlNull(): void | ||
{ | ||
$urlEncodingTwigFilter = new UrlEncodingTwigFilter(); | ||
$result = $urlEncodingTwigFilter->encodeUrl(null); | ||
static::assertNull($result); | ||
} | ||
} |