entityURLGenerator = $entityURLGenerator; $this->cache = $cache; } public function getFilters() { return [ new TwigFilter('entityURL', [$this, 'generateEntityURL']), new TwigFilter('bbCode', [$this, 'parseBBCode'], ['pre_escape' => 'html', 'is_safe' => ['html']]) ]; } public function generateEntityURL(DBElement $entity, string $method = 'info') : string { switch($method) { case 'info': return $this->entityURLGenerator->infoURL($entity); case 'edit': return $this->entityURLGenerator->editURL($entity); case 'create': return $this->entityURLGenerator->createURL($entity); case 'clone': return $this->entityURLGenerator->cloneURL($entity); } throw new \InvalidArgumentException('method is not supported!'); } public function parseBBCode(string $bbcode) : string { if($bbcode === '') return ''; $item = $this->cache->getItem('bbcode_' . md5($bbcode)); if(!$item->isHit()) { $xml = TextFormatter::parse($bbcode); $item->set(TextFormatter::render($xml)); $this->cache->save($item); } return $item->get(); } }