| 
					
				 | 
			
			
				@@ -0,0 +1,64 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+<?php 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+namespace App\Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use App\Entity\Article; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use Symfony\Component\Routing\Generator\UrlGeneratorInterface; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use App\Repository\ArticleRepository; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use Laminas\Feed\Writer\Entry; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use Laminas\Feed\Writer\Feed; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+use Symfony\Component\Routing\RouterInterface; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+class FeedService 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public const ATOM = 'atom'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public const RSS = 'rss'; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function __construct( 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        protected ArticleRepository $articleRepository, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        protected UrlGeneratorInterface $router, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        protected MarkdownParser $markdownParser, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        protected ParameterBagInterface $parameterBagInterface 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    ) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function createFeed(array $articles, string $type = self::RSS, \DateTimeImmutable $updatedAt): string 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $feed = new Feed(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $feed->setTitle($this->parameterBagInterface->get('title')); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $feed->setLink($this->router->generate('app_index', [], RouterInterface::ABSOLUTE_URL)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $feed->setFeedLink($this->router->generate('app_feed', ['type' => $type], RouterInterface::ABSOLUTE_URL), $type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $feed->setDescription('Derniers articles du blog'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $feed->setLanguage('fr'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        $feed->setDateModified($updatedAt); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        foreach($this->getItems($articles) as $item) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $feed->addEntry($item); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return $feed->export($type); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public function getItems($articles): \Iterator 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        foreach($articles as $article) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            /** @var Article $article */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $item = new Entry(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $item 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ->setTitle($article->getTitle()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ->setLink($this->router->generate('app_view', ['slug' => $article->getSlug()], RouterInterface::ABSOLUTE_URL)) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ->setDateCreated($article->getPublicationDate()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ->setDateModified($item->getDateCreated()) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ->addAuthor(['name' => (string) $article->getAuthor()]) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            # Fix pour supprimer le allowfullscreen récupéré par l'extension embed pour youtube 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $content = $this->markdownParser->convertToHtml($article->getContent()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $content = str_replace('allowfullscreen', 'allowfullscreen="true"', $content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            $item->setContent($content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            ; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            yield $item; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 |