src/Twig/GitLastCommit.php line 49

  1. <?php
  2. namespace App\Twig;
  3. use App\Handler\Git;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  8. use Twig\Environment;
  9. /**
  10.  * Class GitLastCommit
  11.  * @package App\Twig
  12.  */
  13. class GitLastCommit implements EventSubscriberInterface
  14. {
  15.     /**
  16.      * @var Environment
  17.      */
  18.     private Environment $twig;
  19.     /**
  20.      * @var Git
  21.      */
  22.     private Git $git;
  23.     /**
  24.      * LastNotifications constructor.
  25.      * @param Environment $twig
  26.      * @param Git $git
  27.      */
  28.     public function __construct(Environment $twigGit $git)
  29.     {
  30.         $this->twig $twig;
  31.         $this->git $git;
  32.     }
  33.     /**
  34.      * @return array|string[]
  35.      */
  36.     public static function getSubscribedEvents()
  37.     {
  38.         return [
  39.             KernelEvents::CONTROLLER => 'lastCommit'
  40.         ];
  41.     }
  42.     public function lastCommit()
  43.     {
  44.         $this->twig->addGlobal('lastCommitDate'$this->git->getLastCommitDate());
  45.     }
  46. }