<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
php-programmist / yandex-turbo-rss-generator-bundle example snippets
//src/Adapter/RssContentAdapter.php
namespace App\Adapter;
use App\Entity\Content;
use PhpProgrammist\YandexTurboRssGeneratorBundle\Adapters\BasePageInterface;
use PhpProgrammist\YandexTurboRssGeneratorBundle\Adapters\RssBaseAdapter;
use PhpProgrammist\YandexTurboRssGeneratorBundle\RssItem;
class RssContentAdapter extends RssBaseAdapter
{
protected function adapt(array $original_items, BasePageInterface $base_page)
{
/** @var Content $original_item */
foreach ($original_items as $original_item) {
$item = new RssItem(
$original_item->getId(),
$original_item->getPath(),
$original_item->getName(),
$original_item->getDate(),
$original_item->getText()
);
$item->setAllBreadcrumbs('Home',$base_page);
$this->addItem($item);
}
}
}
//src/Controller/NewsController.php
namespace App\Controller;
use PhpProgrammist\YandexTurboRssGeneratorBundle\Adapters\BasePage;
use PhpProgrammist\YandexTurboRssGeneratorBundle\YandexTurboRssGenerator;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;
class NewsController extends AbstractController
{
/**
* @Route("/news/rss.xml", name="news_rss")
*/
public function rss(ContentRepository $content_repository)
{
$items = $content_repository->findAll();
$base_page = new BasePage('News','Channel description','/news/');
$adapter = new RssNewsAdapter($items, $base_page);
return $this->rss_generator->render($adapter, $base_page);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.