<?php
/**
* Created by simpson <simpsonwork@gmail.com>
* Date: 11.12.2019
* Time: 15:32
*/
namespace App\Twig;
use App\Service\ResponsiveAssetsService;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class ResponsiveAssetExtension extends AbstractExtension
{
public function __construct(
private ResponsiveAssetsService $responsiveAssetsService
) {}
public function getFunctions()
{
return [
new TwigFunction('responsive_asset', [$this, 'getResponsiveImageUrl']),
new TwigFunction('stream_asset', [$this, 'getStreamUrl']),
];
}
public function getResponsiveImageUrl(string $path, string $packageName, string $presetName, string $extension = 'jpg'): string
{
return $this->responsiveAssetsService->getResponsiveImageUrl($path, $packageName, $presetName, $extension);
}
public function getStreamUrl(string $path, string $packageName): string
{
return $this->responsiveAssetsService->getStreamUrl($path, $packageName);
}
}