Search by

mekras / atompub

Mekras

Atom Publishing Protocol support library

Package info

github.com/mekras/atompub

pkg:composer/mekras/atompub

Statistics

Installs: 11 050

Dependents: 1

Suggesters: 0

Stars: 1

Open Issues: 0

v1.0.0 2016-08-17 14:24 UTC

This package is auto-updated.

Last update: 2026-11-13 17:57:11 UTC


README

Maintenance status

This project is no longer maintained and is archived for historical reference. No further updates or fixes, including security fixes, are planned. Compatibility with current PHP versions and dependencies has not been verified. The documentation and examples below describe the historical version.

Latest Stable Version License Build Status Coverage Status

Purpose

This library is designed to work with the AtomPub documents in an object-oriented style. It does not contain the functionality to download or display documents.

This library is an extension of the package Atom.

Parsing documents

use Mekras\Atom\Document\EntryDocument;
use Mekras\Atom\Document\FeedDocument;
use Mekras\Atom\Exception\AtomException;
use Mekras\AtomPub\Document\CategoryDocument;
use Mekras\AtomPub\Document\ServiceDocument;
use Mekras\AtomPub\DocumentFactory;

$factory = new DocumentFactory;

$xml = file_get_contents('http://example.com/atom');
try {
    $document = $factory->parseXML($xml);
} catch (AtomException $e) {
    die($e->getMessage());
}

if ($document instanceof CategoryDocument) {
    $categories = $document->getCategories();
    //...
} elseif ($document instanceof ServiceDocument) {
    $workspaces = $document->getWorkspaces();
    //...
} elseif ($document instanceof FeedDocument) {
    $feed = $document->getFeed();
    //...
} elseif ($document instanceof EntryDocument) {
    $entry = $document->getEntry();
    //...
}

Creating entries

use Mekras\AtomPub\DocumentFactory;

$factory = new DocumentFactory;
$document = $factory->createDocument('atom:entry');
$entry = $document->getEntry();
$entry->addId('urn:entry:0001');
$entry->addTitle('Entry Title');
$entry->addAuthor('Author 1')->setEmail('foo@example.com');
$entry->addContent('<h1>Entry content</h1>', 'html');
$entry->addCategory('tag1')->setLabel('Tag label')->setScheme('http://example.com/scheme');
$entry->addUpdated(new \DateTime());

// Suppose that $httpClient is some kind of HTTP client...
$httpClient->sendRequest('POST', 'http://example.com/', (string) $document);