Skip to content

Commit

Permalink
Rewritten according to the new atom package extension model.
Browse files Browse the repository at this point in the history
  • Loading branch information
mekras committed Jul 7, 2016
1 parent 2f9bdd6 commit 8e0043f
Show file tree
Hide file tree
Showing 21 changed files with 286 additions and 310 deletions.
10 changes: 0 additions & 10 deletions src/AtomPub.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Mekras\AtomPub;

use Mekras\Atom\Atom;
use Mekras\AtomPub\Extension\AtomPubDocuments;

/**
* XML to AtomPub Document converter.
Expand All @@ -26,13 +25,4 @@ class AtomPub extends Atom
* @since 1.0
*/
const NS = 'http://www.w3.org/2007/app';

/**
* AtomPub constructor.
*/
public function __construct()
{
parent::__construct();
$this->registerDocumentType(new AtomPubDocuments());
}
}
8 changes: 5 additions & 3 deletions src/Document/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use Mekras\Atom\Atom;
use Mekras\Atom\Document\Document as AtomDocument;
use Mekras\Atom\Extensions;
use Mekras\AtomPub\AtomPub;

/**
Expand All @@ -23,15 +24,16 @@ abstract class Document extends AtomDocument
/**
* Create document.
*
* @param \DOMDocument|null $document
* @param Extensions $extensions Extension registry.
* @param \DOMDocument|null $document Source document.
*
* @throws \InvalidArgumentException
*
* @since 1.0
*/
public function __construct($document = null)
public function __construct(Extensions $extensions, \DOMDocument $document = null)
{
parent::__construct($document);
parent::__construct($extensions, $document);
if (null === $document) {
$this->getDomDocument()->documentElement
->setAttributeNS(Atom::XMLNS, 'xmlns:atom', Atom::NS);
Expand Down
40 changes: 0 additions & 40 deletions src/Document/EntryDocument.php

This file was deleted.

40 changes: 0 additions & 40 deletions src/Document/FeedDocument.php

This file was deleted.

5 changes: 3 additions & 2 deletions src/Document/ServiceDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function () {
$workspaces = [];
$items = $this->getDomElement()->getElementsByTagNameNS($this->ns(), 'workspace');
foreach ($items as $item) {
$workspaces[] = new Workspace($item);
$workspaces[] = $this->getExtensions()->parseElement($item);
}

return $workspaces;
Expand All @@ -58,7 +58,8 @@ public function addWorkspace($title)
{
$workspaces = $this->getWorkspaces();

$workspace = new Workspace($this);
/** @var Workspace $workspace */
$workspace = $this->getExtensions()->createElement($this, 'workspace');
$workspace->setTitle($title);

$workspaces[] = $workspace;
Expand Down
30 changes: 30 additions & 0 deletions src/DocumentFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php
/**
* Atom Publishing Protocol support
*
* @author Михаил Красильников <m.krasilnikov@yandex.ru>
* @license MIT
*/
namespace Mekras\AtomPub;

use Mekras\Atom\DocumentFactory as BaseDocumentFactory;
use Mekras\AtomPub\Extension\AtomPubExtension;

/**
* XML to AtomPub Document converter.
*
* @since 1.0
*
* @api
*/
class DocumentFactory extends BaseDocumentFactory
{
/**
* Create new factory.
*/
public function __construct()
{
parent::__construct();
$this->getExtensions()->register(new AtomPubExtension());
}
}
4 changes: 2 additions & 2 deletions src/Element/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function () {
/** @var \DOMNodeList $items */
$items = $this->query('atom:entry');
foreach ($items as $item) {
$result[] = new Entry($item);
$result[] = $this->getExtensions()->parseElement($item);
}

return $result;
Expand All @@ -55,6 +55,6 @@ function () {
*/
public function addEntry()
{
return new Entry($this);
return $this->getExtensions()->createElement($this, 'entry');
}
}
5 changes: 3 additions & 2 deletions src/Element/Workspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function () {
/** @var \DOMNodeList $items */
$items = $this->query('app:collection');
foreach ($items as $item) {
$result[] = new Collection($item);
$result[] = $this->getExtensions()->parseElement($item);
}

return $result;
Expand All @@ -61,7 +61,8 @@ public function addCollection($title)
{
$collections = $this->getCollections();

$collection = new Collection($this);
/** @var Collection $collection */
$collection = $this->getExtensions()->createElement($this, 'collection');
$collection->setTitle($title);

$collections[] = $collection;
Expand Down
57 changes: 0 additions & 57 deletions src/Extension/AtomPubDocuments.php

This file was deleted.

0 comments on commit 8e0043f

Please sign in to comment.