1. Go to this page and download the library: Download debril/rss-atom-bundle library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
debril / rss-atom-bundle example snippets
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
// ...
// register the bundle here
new Debril\RssAtomBundle\DebrilRssAtomBundle(),
namespace App\Feed;
class Consumer
{
/**
* @type \FeedIo\FeedIo
*/
private $feedIo;
public function __construct(FeedIo $feedIo)
{
$this->feedIo = $feedIo;
}
}
// get feedio
$feedIo = $this->container->get('feedio');
// this date is used to fetch only the latest items
$modifiedSince = new \DateTime($date);
// the feed you want to read
$url = 'http://host.tld/feed';
// now fetch its (fresh) content
$feed = $feedIo->read($url, new \Acme\Entity\Feed, $modifiedSince)->getFeed();
foreach ( $feed as $item ) {
echo "item title : {$item->getTitle()} \n ";
// getMedias() returns enclosures if any
$medias = $item->getMedias();
}
// get feedio
$feedIo = $this->container->get('feedio');
// this date is used to fetch only the latest items
$modifiedSince = new \DateTime($date);
// the feed you want to read
$url = 'http://host.tld/feed';
// now fetch its (fresh) content
$feed = $feedIo->readSince($url, $modifiedSince)->getFeed();
# src/Feed/Provider.php
namespace App\Feed;
use FeedIo\Feed;
use FeedIo\FeedInterface;
use FeedIo\Feed\Item;
use Debril\RssAtomBundle\Provider\FeedContentProviderInterface;
class Provider implements FeedProviderInterface
{
/**
* @param array $options
* @return \FeedIo\FeedInterface
* @throws \Debril\RssAtomBundle\Exception\FeedNotFoundException
*/
public function getFeed(Request $request) : FeedInterface
{
// build the feed the way you want
$feed = new Feed();
$feed->setTitle('your title');
foreach($this->getItems() as $item ) {
$feed->add($item);
}
return $feed;
}
protected function getItems()
{
foreach($this->fetchFromStorage() as $storedItem) {
$item = new Item;
$item->setTitle($storedItem->getTitle());
// ...
yield $item;
}
}
protected function fetchFromStorage()
{
// query the database to fetch items
}
}
interface FeedInterface extends \Iterator, NodeInterface
{
/**
* This method MUST return the feed's full URL
* @return string
*/
public function getUrl();
/**
* @param string $url
* @return FeedInterface
*/
public function setUrl($url);
// Full source can be read in the repository .......
use Vendor\Bundle\DependencyInjection\Compiler\OverrideRssAtomBundleProviderCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class VendorBundle extends Bundle
{
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new OverrideRssAtomBundleProviderCompilerPass());
}
}
use Vendor\Bundle\Provider\FeedProvider;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
class OverrideRssAtomBundleProviderCompilerPass implements CompilerPassInterface
{
public function process(ContainerBuilder $container)
{
$definition = $container->getDefinition('debril.rss_atom.provider');
$definition->setClass(FeedProvider::class);
$definition->addArgument(new Reference('my.service1'));
$definition->addArgument(new Reference('my.service2'));
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.