Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mekras/atompub
Atom Publishing Protocol support library
https://github.com/mekras/atompub
Last synced: 26 days ago
JSON representation
Atom Publishing Protocol support library
- Host: GitHub
- URL: https://github.com/mekras/atompub
- Owner: mekras
- License: mit
- Created: 2016-06-28T07:54:40.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-08-17T14:25:13.000Z (about 8 years ago)
- Last Synced: 2024-08-09T13:12:33.526Z (3 months ago)
- Language: PHP
- Size: 48.8 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# [Atom Publishing Protocol](http://tools.ietf.org/html/rfc5023) support library
[![Latest Stable Version](https://poser.pugx.org/mekras/atompub/v/stable.png)](https://packagist.org/packages/mekras/atompub)
[![License](https://poser.pugx.org/mekras/atompub/license.png)](https://packagist.org/packages/mekras/atompub)
[![Build Status](https://travis-ci.org/mekras/atompub.svg?branch=master)](https://travis-ci.org/mekras/atompub)
[![Coverage Status](https://coveralls.io/repos/mekras/atompub/badge.svg?branch=master&service=github)](https://coveralls.io/github/mekras/atompub?branch=master)## Purpose
This library is designed to work with the [AtomPub](http://tools.ietf.org/html/rfc5023) 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](https://packagist.org/packages/mekras/atom).
## Parsing documents
```php
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
```php
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('[email protected]');
$entry->addContent('Entry content
', '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);
```