HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: /var/www/vhost/disk-apps/magento.bikenow.co/vendor/magento/module-rss/Model/Rss.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

declare(strict_types=1);

namespace Magento\Rss\Model;

use Magento\Framework\App\CacheInterface;
use Magento\Framework\App\FeedFactoryInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\App\Rss\DataProviderInterface;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Exception\RuntimeException;
use Magento\Framework\Serialize\SerializerInterface;

/**
 * Provides functionality to work with RSS feeds
 *
 * @api
 * @since 100.0.2
 */
class Rss
{
    /**
     * @var DataProviderInterface
     */
    protected $dataProvider;

    /**
     * @var CacheInterface
     */
    protected $cache;

    /**
     * @var FeedFactoryInterface
     */
    private $feedFactory;

    /**
     * @var SerializerInterface
     */
    private $serializer;

    /**
     * Rss constructor
     *
     * @param CacheInterface $cache
     * @param SerializerInterface|null $serializer
     * @param FeedFactoryInterface|null $feedFactory
     */
    public function __construct(
        CacheInterface $cache,
        SerializerInterface $serializer = null,
        FeedFactoryInterface $feedFactory = null
    ) {
        $this->cache = $cache;
        $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
        $this->feedFactory = $feedFactory ?: ObjectManager::getInstance()->get(FeedFactoryInterface::class);
    }

    /**
     * Returns feeds
     *
     * @return array
     */
    public function getFeeds()
    {
        if ($this->dataProvider === null) {
            return [];
        }
        $cacheKey = $this->dataProvider->getCacheKey();
        $cacheLifeTime = $this->dataProvider->getCacheLifetime();

        $cache = $cacheKey && $cacheLifeTime ? $this->cache->load($cacheKey) : false;
        if ($cache) {
            return $this->serializer->unserialize($cache);
        }

        // serializing data to make sure all Phrase objects converted to a string
        $serializedData = $this->serializer->serialize($this->dataProvider->getRssData());

        if ($cacheKey && $cacheLifeTime) {
            $this->cache->save($serializedData, $cacheKey, ['rss'], $cacheLifeTime);
        }

        return $this->serializer->unserialize($serializedData);
    }

    /**
     * Sets data provider
     *
     * @param DataProviderInterface $dataProvider
     * @return $this
     */
    public function setDataProvider(DataProviderInterface $dataProvider)
    {
        $this->dataProvider = $dataProvider;

        return $this;
    }

    /**
     * Returns rss xml
     *
     * @return string
     * @throws InputException
     * @throws RuntimeException
     */
    public function createRssXml()
    {
        $feed = $this->feedFactory->create($this->getFeeds(), FeedFactoryInterface::FORMAT_RSS);

        return $feed->getFormattedContent();
    }
}