Use a Twig extension to count the years of experience
This commit is contained in:
parent
a516fa11e1
commit
9b19d7a036
10 changed files with 54 additions and 23 deletions
26
src/Opdavies/TwigExtension/OpdaviesTwigExtension.php
Normal file
26
src/Opdavies/TwigExtension/OpdaviesTwigExtension.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue