Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public function getBrowserPath(string $src, string $presetName): string
}

$options = [];
foreach ($preset['options'] as $optionName => $optionParams) {
$presetOptions = $preset['options'] ?? [];
foreach ($presetOptions as $optionName => $optionParams) {
$option = OptionFactory::fromName($optionName, $optionParams);
$options[] = $option->resolve();
}
Expand All @@ -65,7 +66,7 @@ public function getBrowserPath(string $src, string $presetName): string
$source = Encoder::encode($src, true);
}

$path = '/'.$options.'/'.$source.$separator.$preset['format'];
$path = '/'.($options ? $options.'/' : '').$source.$separator.$preset['format'];
$signature = $this->signer->generateSignature($path);

return $this->host.'/'.$signature.$path;
Expand Down
38 changes: 38 additions & 0 deletions tests/ResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,14 @@ public function testWrongPresetName(): void
$this->resolver->getBrowserPath('https://fakeimg.pl/350x200/?text=Mezcalito', 'test');
}

#[DataProvider('localUrlFalsyOptions')]
public function testCreateLocalUrlWithFalsyOption(string $src, string $filter, string $result): void
{
$this->addingContainer();

$this->assertEquals($result, $this->resolver->getBrowserPath($src, $filter));
}

public static function plainUrl(): iterable
{
yield [
Expand Down Expand Up @@ -122,6 +130,25 @@ public static function localUrlWithMediaUrl(): iterable
];
}

public static function localUrlFalsyOptions(): iterable
{
yield [
'src' => 'image.png',
'filter' => 'no_options',
'result' => 'http://localhost:8080/X_PYvMBPKiTcVblydcE_wagAk_jwFeHOM3JoHyiZ5Gk/plain/localhostimage.png@webp',
];
yield [
'src' => 'image.png',
'filter' => 'empty_options',
'result' => 'http://localhost:8080/X_PYvMBPKiTcVblydcE_wagAk_jwFeHOM3JoHyiZ5Gk/plain/localhostimage.png@webp',
];
yield [
'src' => 'image.png',
'filter' => 'null_options',
'result' => 'http://localhost:8080/X_PYvMBPKiTcVblydcE_wagAk_jwFeHOM3JoHyiZ5Gk/plain/localhostimage.png@webp',
];
}

private function addingContainer(bool $withMediaUrl = false, bool $withRequest = true): void
{
$container = $this->createContainer($withMediaUrl);
Expand Down Expand Up @@ -160,6 +187,17 @@ private function createContainer(bool $withMediaUrl = false): ContainerBuilder
'rotate' => ['angle' => 270],
],
],
'no_options' => [
'format' => 'webp',
],
'empty_options' => [
'format' => 'webp',
'options' => [],
],
'null_options' => [
'format' => 'webp',
'options' => null,
],
],
];

Expand Down