Ran rector to convert some our twig extensions to use #[AsTwigXX] attributes

This commit is contained in:
Jan Böhmer 2026-02-14 23:53:31 +01:00
parent c8b1320bb9
commit f69b0889eb
11 changed files with 34 additions and 67 deletions

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
*/
namespace App\Twig;
use Twig\Attribute\AsTwigFunction;
use App\Settings\SettingsIcon;
use Symfony\Component\HttpFoundation\Request;
use App\Services\LogSystem\EventCommentType;
@ -31,23 +32,14 @@ use Twig\TwigFunction;
use App\Services\LogSystem\EventCommentNeededHelper;
use Twig\Extension\AbstractExtension;
final class MiscExtension extends AbstractExtension
final class MiscExtension
{
public function __construct(private readonly EventCommentNeededHelper $eventCommentNeededHelper)
{
}
public function getFunctions(): array
{
return [
new TwigFunction('event_comment_needed', $this->evenCommentNeeded(...)),
new TwigFunction('settings_icon', $this->settingsIcon(...)),
new TwigFunction('uri_without_host', $this->uri_without_host(...))
];
}
private function evenCommentNeeded(string|EventCommentType $operation_type): bool
#[AsTwigFunction(name: 'event_comment_needed')]
public function evenCommentNeeded(string|EventCommentType $operation_type): bool
{
if (is_string($operation_type)) {
$operation_type = EventCommentType::from($operation_type);
@ -63,7 +55,8 @@ final class MiscExtension extends AbstractExtension
* @return string|null
* @throws \ReflectionException
*/
private function settingsIcon(string|object $objectOrClass): ?string
#[AsTwigFunction(name: 'settings_icon')]
public function settingsIcon(string|object $objectOrClass): ?string
{
//If the given object is a proxy, then get the real object
if (is_a($objectOrClass, SettingsProxyInterface::class)) {
@ -82,6 +75,7 @@ final class MiscExtension extends AbstractExtension
* @param Request $request
* @return string
*/
#[AsTwigFunction(name: 'uri_without_host')]
public function uri_without_host(Request $request): string
{
if (null !== $qs = $request->getQueryString()) {