Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Attributes
Rss Class Reference

Public Member Functions

 __construct (\Magento\Framework\App\CacheInterface $cache, SerializerInterface $serializer=null, FeedFactoryInterface $feedFactory=null)
 
 getFeeds ()
 
 setDataProvider (DataProviderInterface $dataProvider)
 
 createRssXml ()
 

Protected Attributes

 $dataProvider
 
 $cache
 

Detailed Description

Provides functionality to work with RSS feeds

@api

Since
100.0.2

Definition at line 22 of file Rss.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\CacheInterface  $cache,
SerializerInterface  $serializer = null,
FeedFactoryInterface  $feedFactory = null 
)

Rss constructor

Parameters
\Magento\Framework\App\CacheInterface$cache
SerializerInterface | null$serializer
FeedFactoryInterface | null$feedFactory

Definition at line 51 of file Rss.php.

55  {
56  $this->cache = $cache;
57  $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
58  $this->feedFactory = $feedFactory ?: ObjectManager::getInstance()->get(FeedFactoryInterface::class);
59  }

Member Function Documentation

◆ createRssXml()

createRssXml ( )
Returns
string
Exceptions

Definition at line 107 of file Rss.php.

108  {
109  $feed = $this->feedFactory->create($this->getFeeds(), FeedFactoryInterface::FORMAT_RSS);
110  return $feed->getFormattedContent();
111  }

◆ getFeeds()

getFeeds ( )
Returns
array

Definition at line 64 of file Rss.php.

65  {
66  if ($this->dataProvider === null) {
67  return [];
68  }
69  $cache = false;
70  if ($this->dataProvider->getCacheKey() && $this->dataProvider->getCacheLifetime()) {
71  $cache = $this->cache->load($this->dataProvider->getCacheKey());
72  }
73 
74  if ($cache) {
75  return $this->serializer->unserialize($cache);
76  }
77 
78  $data = $this->dataProvider->getRssData();
79 
80  if ($this->dataProvider->getCacheKey() && $this->dataProvider->getCacheLifetime()) {
81  $this->cache->save(
82  $this->serializer->serialize($data),
83  $this->dataProvider->getCacheKey(),
84  ['rss'],
85  $this->dataProvider->getCacheLifetime()
86  );
87  }
88 
89  return $data;
90  }

◆ setDataProvider()

setDataProvider ( DataProviderInterface  $dataProvider)
Parameters
DataProviderInterface$dataProvider
Returns
$this

Definition at line 96 of file Rss.php.

97  {
98  $this->dataProvider = $dataProvider;
99  return $this;
100  }

Field Documentation

◆ $cache

$cache
protected

Definition at line 32 of file Rss.php.

◆ $dataProvider

$dataProvider
protected

Definition at line 27 of file Rss.php.


The documentation for this class was generated from the following file: