|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
# src/Feed/provider.php |
|
4
|
|
|
|
|
5
|
|
|
namespace App\Feed; |
|
6
|
|
|
|
|
7
|
|
|
// this part assumes that you published "Post" entities |
|
8
|
|
|
use App\Entity\Post; |
|
9
|
|
|
use App\Repository\PostRepository; |
|
10
|
|
|
|
|
11
|
|
|
// All you really need to create a feed |
|
12
|
|
|
use Debril\RssAtomBundle\Provider\FeedProviderInterface; |
|
13
|
|
|
use Doctrine\Bundle\DoctrineBundle\Registry; |
|
14
|
|
|
use FeedIo\Feed; |
|
15
|
|
|
use FeedIo\Feed\Node\Category; |
|
16
|
|
|
use FeedIo\FeedInterface; |
|
17
|
|
|
use Psr\Log\LoggerInterface; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
19
|
|
|
use Symfony\Component\Routing\Router; |
|
20
|
|
|
|
|
21
|
|
|
class Provider implements FeedProviderInterface |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
protected $logger; |
|
25
|
|
|
|
|
26
|
|
|
protected $registry; |
|
27
|
|
|
|
|
28
|
|
|
protected $router; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Provider constructor. |
|
32
|
|
|
* @param LoggerInterface $logger |
|
33
|
|
|
* @param Registry $registry |
|
34
|
|
|
* @param Router $router |
|
35
|
|
|
*/ |
|
36
|
|
|
public function __construct(LoggerInterface $logger, Registry $registry, Router $router) |
|
37
|
|
|
{ |
|
38
|
|
|
$this->logger = $logger; |
|
39
|
|
|
$this->registry = $registry; |
|
40
|
|
|
$this->router = $router; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param array $options |
|
|
|
|
|
|
45
|
|
|
* @return FeedInterface |
|
46
|
|
|
*/ |
|
47
|
|
|
public function getFeed(Request $request) : FeedInterface |
|
48
|
|
|
{ |
|
49
|
|
|
$feed = new Feed(); |
|
50
|
|
|
$feed->setTitle('Feed Title') |
|
51
|
|
|
->setLink('Feed URL') |
|
52
|
|
|
->setDescription('Feed description') |
|
53
|
|
|
->setPublicId('Feed ID'); |
|
54
|
|
|
|
|
55
|
|
|
$lastPostPublicationDate = null; |
|
56
|
|
|
|
|
57
|
|
|
$posts = $this->getPosts(); |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* @var \App\Entity\Post $post |
|
61
|
|
|
*/ |
|
62
|
|
|
foreach ($posts as $post) { |
|
63
|
|
|
$lastPostPublicationDate = is_null($lastPostPublicationDate) ? $post->getPublicationDate():$lastPostPublicationDate; |
|
64
|
|
|
|
|
65
|
|
|
$item = new Feed\Item(); |
|
66
|
|
|
$item->setTitle($post->getTitle()); |
|
67
|
|
|
|
|
68
|
|
|
$category = new Category(); |
|
69
|
|
|
$category->setLabel($post->getCategory()); |
|
70
|
|
|
$item->addCategory($category); |
|
71
|
|
|
|
|
72
|
|
|
$item->setLastModified($post->getPublicationDate()); |
|
73
|
|
|
|
|
74
|
|
|
// ... and all the stuff about content, public id, etc ... |
|
75
|
|
|
|
|
76
|
|
|
$feed->add($item); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
// if the publication date is still empty, set it the current Date |
|
80
|
|
|
$lastPostPublicationDate = is_null($lastPostPublicationDate) ? new \DateTime():$lastPostPublicationDate; |
|
81
|
|
|
$feed->setLastModified($lastPostPublicationDate); |
|
82
|
|
|
|
|
83
|
|
|
return $feed; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* You'll need to code this |
|
88
|
|
|
* @return array |
|
89
|
|
|
*/ |
|
90
|
|
|
protected function getPosts() |
|
91
|
|
|
{ |
|
92
|
|
|
return []; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
} |
|
96
|
|
|
|
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.