<?php
namespace App\Twig;
use App\Services\Articles;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;
use Twig\TwigFunction;
class ArticlesExtension extends AbstractExtension
{
public function __construct(Articles $articles)
{
$this->articles = $articles;
}
/**
* {@inheritdoc}
*/
public function getFunctions(): array
{
return [
new TwigFunction('articleResumeChain', [$this, 'articleResumeChain']),
new TwigFunction('forTags', [$this, 'forTags']),
new TwigFunction('rewriteTag', [$this, 'rewriteTag']),
new TwigFunction('reverseRewriteTag', [$this, 'reverseRewriteTag']),
new TwigFunction('getArticles', [$this, 'getArticles']),
];
}
public function getArticles($locale,$number)
{
return $this->articles->getLast($locale,$number);
}
public function articleResumeChain($chain,$numbers)
{
return $this->articles->resumeDescription($chain,$numbers);
}
public function forTags($tags)
{
return $this->articles->forTags($tags);
}
public function rewriteTag($tag)
{
return $this->articles->rewriteTag($tag);
}
public function reverseRewriteTag($tag)
{
return $this->articles->reverseRewriteTag($tag);
}
}