Skip to content

Commit

Permalink
feat: imgproxy in Twig
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarlovi committed Dec 11, 2023
1 parent 3887162 commit 1bf6068
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
15 changes: 15 additions & 0 deletions psalm.baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,14 @@
<code><![CDATA[$GLOBALS['YASSG_BASEDIR']]]></code>
<code><![CDATA[$context['_path']]]></code>
</MixedArgument>
<MixedAssignment>
<code><![CDATA[$context['_path']]]></code>
<code><![CDATA[$context['_path']]]></code>
<code>$item</code>
</MixedAssignment>
<MixedPropertyFetch>
<code><![CDATA[$options['self']->__path]]></code>
</MixedPropertyFetch>
<PossiblyNullArgument>
<code><![CDATA[$this->imgproxyUrl]]></code>
</PossiblyNullArgument>
Expand Down Expand Up @@ -632,12 +640,19 @@
<code>$locale</code>
<code>$locale</code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code>$key</code>
</MixedArgumentTypeCoercion>
<MixedArrayOffset>
<code><![CDATA[$this->cache[$this->class][$locale]]]></code>
</MixedArrayOffset>
<MixedAssignment>
<code>$locale</code>
<code>$locale</code>
<code>$metadata[$key]</code>
<code>$object</code>
<code>$value</code>
<code>$value</code>
</MixedAssignment>
<MixedInferredReturnType>
<code>T</code>
Expand Down
7 changes: 3 additions & 4 deletions src/Bridge/Twig/Extension/ThumbnailExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

use Sigwin\YASSG\Asset\AssetFetch;
use Sigwin\YASSG\AssetQueue;
use Sigwin\YASSG\Locatable;
use Symfony\Component\Asset\Packages;
use Symfony\Component\HttpFoundation\RequestStack;
use Twig\Extension\AbstractExtension;
Expand All @@ -30,17 +29,17 @@ public function getFunctions(): array
return [
new TwigFunction('yassg_thumbnail', function (array $context, string $path, array $options = []): string {
if (str_starts_with($path, './')) {
if (!isset($context['_path'])) {
if (! isset($context['_path'])) {
if (isset($options['self'])) {
$context['_path'] = $options['self']->__path;
} else {
$candidates = [];
foreach ($context as $item) {
if (is_object($item) && property_exists($item, '__path')) {
if (\is_object($item) && property_exists($item, '__path')) {
$candidates[] = $item;
}
}
if (count($candidates) !== 1) {
if (\count($candidates) !== 1) {
throw new \RuntimeException('Cannot use yassg_thumbnail() without a single Locatable object in context, pass {self: object} as the second argument');
}
$context['_path'] = $candidates[0]->__path;
Expand Down
3 changes: 3 additions & 0 deletions src/Storage/DenormalizingStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ private function denormalize(string $id, array $data, array $context): object

// attach metadata to the object as dynamic properties
foreach ($metadata as $key => $value) {
/**
* @phpstan-ignore-next-line
*/
$object->{$key} = $value;
}

Expand Down

0 comments on commit 1bf6068

Please sign in to comment.