ddebin/atom-generator

Atom feed generator

0.3.3 2024-03-19 14:54 UTC

This package is auto-updated.

Last update: 2024-10-19 16:08:30 UTC


README

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).