Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Remove manual Glide filenames #9913

Merged
merged 2 commits into from
Apr 16, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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