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.
30 lines
552 B
30 lines
552 B
2 years ago
|
<?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());
|
||
|
}
|
||
|
}
|