You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
29 lines
552 B
29 lines
552 B
<?php |
|
|
|
declare(strict_types=1); |
|
|
|
namespace App\Twig; |
|
|
|
use App\Entity\Url; |
|
use App\Hasher; |
|
use Twig\Extension\AbstractExtension; |
|
use Twig\TwigFunction; |
|
|
|
class HasherExtension extends AbstractExtension |
|
{ |
|
public function __construct(private Hasher $hasher) |
|
{ |
|
} |
|
|
|
public function getFunctions() |
|
{ |
|
return [ |
|
new TwigFunction('hasher_encode', [$this, 'encode']), |
|
]; |
|
} |
|
|
|
public function encode(Url $url): string |
|
{ |
|
return $url->getCustomString() ?? $this->hasher->encode($url->getId()); |
|
} |
|
}
|
|
|