-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
71 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Bridge\Glide\Bundle; | ||
|
||
use League\Glide\ServerFactory; | ||
|
||
class DecoratingApiServerFactory extends ServerFactory | ||
{ | ||
public function getApi() | ||
{ | ||
// @phpstan-ignore-next-line | ||
return new SkippingMimeTypesApi(parent::getApi(), $this->config['skipped_types'] ?? []); | ||
} | ||
|
||
public static function create(array $config = []) | ||
{ | ||
$server = parent::create($config); | ||
$decoratedFactory = (new self($config)); | ||
|
||
$server->setApi($decoratedFactory->getApi()); | ||
|
||
return $server; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Bridge\Glide\Bundle; | ||
|
||
use League\Glide\Api\ApiInterface; | ||
use Symfony\Component\Mime\MimeTypes; | ||
use Symfony\Component\Mime\MimeTypesInterface; | ||
|
||
/** | ||
* An API implementation allowing to skip Glide resize on some specific MIME types | ||
* (usually unsupported by Glide, or removing GIF animations for instance), | ||
* but still allowing to pass through Glide's server and move the images to a properly public location. | ||
*/ | ||
class SkippingMimeTypesApi implements ApiInterface | ||
{ | ||
public function __construct( | ||
private ApiInterface $decorated, | ||
private array $skippedTypes = ['image/gif'], | ||
private MimeTypesInterface $types = new MimeTypes() | ||
) { | ||
} | ||
|
||
public function run($source, array $params): string | ||
{ | ||
if (\in_array($this->types->guessMimeType($source), $this->skippedTypes, true)) { | ||
return (string) file_get_contents($source); | ||
} | ||
|
||
return $this->decorated->run($source, $params); | ||
} | ||
} |
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