Skip to content

ddebin/atom-generator

Repository files navigation

CI Codecov PHP from Packagist Packagist Version Packagist

Atom feed generator

This library is an [Atom](https://en.wikipedia.org/wiki/Atom_(Web_standard) feed generator, PHP 7.1+, fully typed (PHPStan level 7, 100% code coverage). Follows W3C standard (RFC 4287).

Installing

Install via Composer:

composer require ddebin/atom-generator

Example

<?php

include_once 'vendor/autoload.php';

$entry = new AtomGenerator\Entry();
$entry->setTitle('Post', 'text');
$entry->setId('tag:id');
$entry->setContent('Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.', 'text');
$entry->setUpdatedDateTime(new DateTime('2019-05-04T21:00:40Z'));

$feed = new AtomGenerator\Feed();
$feed->setTitle('Blog');
$feed->setUpdatedDateTime(new DateTime('now'));
$feed->addEntry($entry);

assert(AtomGenerator\Feed::validate($feed->getDocument()));

echo $feed->saveXML();

Validation

A validation tool is included with static method Feed::validate. It uses a Relax NG schema coming from https://validator.w3.org/feed/docs/rfc4287.html#schema (inspired by https://cweiske.de/tagebuch/atom-validation.htm).