Skip to content
Open
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: 4 additions & 1 deletion src/DI/ImageStorageExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
->setType(ImageStorage::class)
->setFactory(ImageStorage::class)
->setArguments((array) $config);

$builder->addDefinition($this->prefix('latteExtension'))
->setType(LatteExtension::class);

Check failure on line 52 in src/DI/ImageStorageExtension.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

Object operator not indented correctly; expected 12 spaces but found 16

Check failure on line 52 in src/DI/ImageStorageExtension.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

Tabs must be used to indent lines; spaces are not allowed
}

public function beforeCompile(): void
Expand All @@ -56,7 +59,7 @@
$latteFactory = $builder->getDefinition('latte.latteFactory');
assert($latteFactory instanceof FactoryDefinition);

$latteFactory->getResultDefinition()->addSetup('addExtension', [new LatteExtension()]);
$latteFactory->getResultDefinition()->addSetup('addExtension', [$this->prefix('@latteExtension')]);
}

}
10 changes: 8 additions & 2 deletions src/ImageNameScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Contributte\ImageStorage;

use Nette\SmartObject;
use function preg_match;
use function preg_replace;

class ImageNameScript
{
Expand Down Expand Up @@ -48,11 +50,15 @@
public static function fromName(string $name): ImageNameScript
{
$pattern = preg_replace('/__file__/', '(.*)\/([^\/]+)\/(.*?)', self::PATTERN);
preg_match($pattern, $name, $matches);

Check failure on line 53 in src/ImageNameScript.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.2)

Ignored error pattern #^Parameter \#1 \$pattern of function preg_match expects string, string\|null given\.$# (argument.type) in path /home/runner/work/image-storage/image-storage/src/ImageNameScript.php is expected to occur 1 time, but occurred 2 times.

if (empty($matches[0])) {

Check failure on line 54 in src/ImageNameScript.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.2)

Construct empty() is not allowed. Use more strict comparison.

Check failure on line 54 in src/ImageNameScript.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

Expected 1 line after "if", found 0.
$pattern = preg_replace('/__file__/', '(.*)\/(.*?)', self::PATTERN);
preg_match($pattern, $name, $matches);

Check failure on line 56 in src/ImageNameScript.php

View workflow job for this annotation

GitHub Actions / Phpstan / Phpstan (8.2)

Parameter #1 $pattern of function preg_match expects string, string|null given.
array_splice($matches, 2, 0, ['']);
}
$script = new self($matches[0]);

$script->original = $matches[1] . '/' . $matches[2] . '/' . $matches[3] . '.' . $matches[15];
$script->original = $matches[1] . '/' . ($matches[2] !== '' ? $matches[2] . '/' : '') . $matches[3] . '.' . $matches[15];
$script->namespace = $matches[1];
$script->prefix = $matches[2];
$script->name = $matches[3];
Expand Down
24 changes: 18 additions & 6 deletions src/Latte/LatteExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Contributte\ImageStorage\Latte;

use Contributte\ImageStorage\ImageStorage;
use Latte\Compiler\Node;
use Latte\Compiler\Nodes\AuxiliaryNode;
use Latte\Compiler\PrintContext;
Expand All @@ -11,6 +12,10 @@
class LatteExtension extends Extension
{

public function __construct(protected readonly ImageStorage $imageStorage)
{
}

/**
* @return array<mixed>
*/
Expand All @@ -32,7 +37,7 @@
$args = $tag->parser->parseArguments();

return new AuxiliaryNode(
fn (PrintContext $context) => $context->format('$_img = $imageStorage->fromIdentifier(%node); echo "<img src=\"" . $basePath . "/" . $_img->createLink() . "\">";', $args)
fn (PrintContext $context) => $context->format('$_img = $this->global->imageStorage->fromIdentifier(%node); echo "<img src=\"" . $basePath . "/" . $_img->createLink() . "\">";', $args)
);
}

Expand All @@ -41,7 +46,7 @@
$args = $tag->parser->parseArguments();

return new AuxiliaryNode(
fn (PrintContext $context) => $context->format('$_img = $imageStorage->fromIdentifier(%node); echo "<img src=\"" . $baseUrl . "/" . $_img->createLink() . "\">";', $args)
fn (PrintContext $context) => $context->format('$_img = $this->global->imageStorage->fromIdentifier(%node); echo "<img src=\"" . $baseUrl . "/" . $_img->createLink() . "\">";', $args)
);
}

Expand All @@ -50,7 +55,7 @@
$args = $tag->parser->parseArguments();

return new AuxiliaryNode(
fn (PrintContext $context) => $context->format('$_img = $imageStorage->fromIdentifier(%node); echo \' src="\' . $basePath . "/" . $_img->createLink() . \'"\';', $args)
fn (PrintContext $context) => $context->format('$_img = $this->global->imageStorage->fromIdentifier(%node); echo \' src="\' . $basePath . "/" . $_img->createLink() . \'"\';', $args)
);
}

Expand All @@ -59,7 +64,7 @@
$args = $tag->parser->parseArguments();

return new AuxiliaryNode(
fn (PrintContext $context) => $context->format('$_img = $imageStorage->fromIdentifier(%node); echo \' src="\' . $baseUrl . "/" . $_img->createLink() . \'"\';', $args)
fn (PrintContext $context) => $context->format('$_img = $this->global->imageStorage->fromIdentifier(%node); echo \' src="\' . $baseUrl . "/" . $_img->createLink() . \'"\';', $args)
);
}

Expand All @@ -68,7 +73,7 @@
$args = $tag->parser->parseArguments();

return new AuxiliaryNode(
fn (PrintContext $context) => $context->format('$_img = $imageStorage->fromIdentifier(%node); echo $basePath . "/" . $_img->createLink();', $args)
fn (PrintContext $context) => $context->format('$_img = $this->global->imageStorage->fromIdentifier(%node); echo $basePath . "/" . $_img->createLink();', $args)
);
}

Expand All @@ -77,8 +82,15 @@
$args = $tag->parser->parseArguments();

return new AuxiliaryNode(
fn (PrintContext $context) => $context->format('$_img = $imageStorage->fromIdentifier(%node); echo $baseUrl . "/" . $_img->createLink();', $args)
fn (PrintContext $context) => $context->format('$_img = $this->global->imageStorage->fromIdentifier(%node); echo $baseUrl . "/" . $_img->createLink();', $args)
);
}

public function getProviders(): array

Check failure on line 89 in src/Latte/LatteExtension.php

View workflow job for this annotation

GitHub Actions / Codesniffer / Codesniffer (8.2)

Method \Contributte\ImageStorage\Latte\LatteExtension::getProviders() does not have @return annotation for its traversable return value.
{
return [
'imageStorage' => $this->imageStorage, // Register the provider
];
}

}
Loading