src/Twig/GitLastCommit.php line 28

  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Twig;
  4. use App\Handler\Git;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. use Twig\Environment;
  8. final class GitLastCommit implements EventSubscriberInterface
  9. {
  10.     public function __construct(
  11.         private readonly Environment $twig,
  12.         private readonly Git $git
  13.     )
  14.     {
  15.     }
  16.     public static function getSubscribedEvents(): array
  17.     {
  18.         return [
  19.             KernelEvents::CONTROLLER => 'lastCommit'
  20.         ];
  21.     }
  22.     public function lastCommit(): void
  23.     {
  24.         $this->twig->addGlobal('lastCommitDate'$this->git->getLastCommitDate());
  25.     }
  26. }