Guillaume преди 3 години
родител
ревизия
28ccddc252
променени са 1 файла, в които са добавени 16 реда и са изтрити 0 реда
  1. +16
    -0
      Twig/TwigExtension.php

+ 16
- 0
Twig/TwigExtension.php Целия файл

@@ -10,6 +10,7 @@ use Lc\SovBundle\Component\DateComponent;
use Lc\SovBundle\Component\FileComponent;
use Lc\SovBundle\Component\MetaComponent;
use Lc\SovBundle\Component\StringComponent;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Form\Newsletter\NewsletterType;
use Lc\SovBundle\Model\File\FileInterface;
use Lc\SovBundle\Repository\Reminder\ReminderStore;
@@ -96,6 +97,7 @@ class TwigExtension extends AbstractExtension
new TwigFunction('day_by_number', [$this, 'getDayByNumber']),
new TwigFunction('user_current', [$this, 'getUserCurrent']),
new TwigFunction('ea_url_short', [$this, 'generateEaUrl']),
new TwigFunction('is_instance_of', [$this, 'isInstanceOf']),
];
}

@@ -115,6 +117,20 @@ class TwigExtension extends AbstractExtension
];
}

public function isInstanceOf(EntityInterface $entity, string $interfaceName)
{
$reflection = new \ReflectionClass($entity);
$interfaceNameArray = $reflection->getInterfaceNames();

foreach($interfaceNameArray as $interfaceNameEntity) {
if(strpos($interfaceNameEntity, $interfaceName) !== false) {
return true;
}
}

return false;
}

public function sovCache($file)
{
$cacheTime = filemtime($this->kernel->getProjectDir() . '/public' . $file);

Loading…
Отказ
Запис