require __DIR__ . '/../vendor/autoload.php'; if (PHP_SAPI !== 'cli') { die("This script should be executed from console!\n"); } if (2 !== $argc) { die('Usage: php example.php <URL of Atom feed or entry>' . PHP_EOL); } $url = $argv[1]; if (!filter_var($url, FILTER_VALIDATE_URL)) { die(sprintf('It seems that "%s" is not a valid URL', $url) . PHP_EOL); } @($xml = file_get_contents($url)); if (!$xml) { die(sprintf('Failed to read document from "%s"', $url) . PHP_EOL); } $factory = new DocumentFactory(); try { $document = $factory->parseXML($xml); } catch (AtomException $e) { die($e->getMessage() . PHP_EOL); } if ($document instanceof FeedDocument) { $feed = $document->getFeed(); echo 'Feed: ', $feed->getTitle(), PHP_EOL; echo 'Updated: ', $feed->getUpdated()->format('d.m.Y H:i:s'), PHP_EOL; foreach ($feed->getAuthors() as $author) { echo 'Author: ', $author->getName(), PHP_EOL; } foreach ($feed->getEntries() as $entry) { echo PHP_EOL; echo ' Entry: ', $entry->getTitle(), PHP_EOL;
/** * Create new factory. */ public function __construct() { parent::__construct(); $this->getExtensions()->register(new AtomPubExtension()); }