Skip to content

Commit

Permalink
[5.x] Remove manual Glide filenames (#9913)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonvarga committed Apr 16, 2024
1 parent dadf2a2 commit 6a91af9
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 45 deletions.
3 changes: 1 addition & 2 deletions src/Contracts/Imaging/UrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ interface UrlBuilder
*
* @param \Statamic\Contracts\Assets\Asset|string $item
* @param array $params
* @param string|null $filename
* @return string
*/
public function build($item, $params, $filename = null);
public function build($item, $params);
}
22 changes: 1 addition & 21 deletions src/Imaging/GlideImageManipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ class GlideImageManipulator implements ImageManipulator
*/
protected $item_type;

/**
* A custom filename.
*
* @var string|null
*/
protected $filename;

/**
* Methods available in Glide's API.
*
Expand Down Expand Up @@ -106,20 +99,7 @@ public function item($item)
*/
public function build()
{
return $this->builder->build($this->item, $this->params, $this->filename);
}

/**
* Set a custom filename.
*
* @param string $filename
* @return $this
*/
public function filename($filename)
{
$this->filename = $filename;

return $this;
return $this->builder->build($this->item, $this->params);
}

/**
Expand Down
16 changes: 4 additions & 12 deletions src/Imaging/GlideUrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,26 +30,18 @@ public function __construct(array $options = [])
*
* @throws \Exception
*/
public function build($item, $params, $filename = null)
public function build($item, $params)
{
$this->item = $item;

switch ($this->itemType()) {
case 'url':
$path = 'http/'.base64_encode($item);

if (! $filename) {
$filename = Str::afterLast($item, '/');
}

$filename = Str::afterLast($item, '/');
break;
case 'asset':
$path = 'asset/'.base64_encode($this->item->containerId().'/'.$this->item->path());

if (! $filename) {
$filename = Str::afterLast($this->item->path(), '/');
}

$filename = Str::afterLast($this->item->path(), '/');
break;
case 'id':
$path = 'asset/'.base64_encode(str_replace('::', '/', $this->item));
Expand All @@ -63,7 +55,7 @@ public function build($item, $params, $filename = null)

$builder = UrlBuilderFactory::create($this->options['route'], $this->options['key']);

if ($filename) {
if (isset($filename)) {
$path .= Str::ensureLeft(URL::encode($filename), '/');
}

Expand Down
3 changes: 1 addition & 2 deletions src/Imaging/StaticUrlBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ public function __construct(ImageGenerator $generator, array $options = [])
*
* @param \Statamic\Contracts\Assets\Asset|string $item
* @param array $params
* @param string|null $filename
* @return string
*/
public function build($item, $params, $filename = null)
public function build($item, $params)
{
$this->item = $item;
$this->params = $params;
Expand Down
8 changes: 0 additions & 8 deletions tests/Imaging/GlideUrlBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,6 @@ public function testId()
);
}

public function testFilename()
{
$this->assertEquals(
'/img/foo.jpg/custom.png?w=100',
$this->builder->build('/foo.jpg', ['w' => '100'], 'custom.png')
);
}

public function testConfigAddsFilename()
{
$asset = new Asset;
Expand Down

0 comments on commit 6a91af9

Please sign in to comment.