Use a Twig extension to count the years of experience

This commit is contained in:
Oliver Davies 2024-05-03 12:30:24 +01:00
parent a516fa11e1
commit 9b19d7a036
10 changed files with 54 additions and 23 deletions

View file

@ -0,0 +1,26 @@
<?php
namespace App\Opdavies\TwigExtension;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
class OpdaviesTwigExtension extends AbstractExtension
{
public function getFunctions(): array
{
return [
new TwigFunction('get_years_of_experience', [$this, 'getYearsOfExperience']),
];
}
public function getName(): string
{
return 'app.opdavies_twig_extension';
}
public function getYearsOfExperience(): int
{
return (new \DateTimeImmutable())->format('Y') - 2007;
}
}