Skip to content

Commit

Permalink
Rewritten according to the latest atom package changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
mekras committed Jul 7, 2016
1 parent adf88b1 commit 1563b83
Show file tree
Hide file tree
Showing 15 changed files with 102 additions and 155 deletions.
4 changes: 2 additions & 2 deletions src/Document/CategoryDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
namespace Mekras\AtomPub\Document;

use Mekras\Atom\Element\Meta\Categories;
use Mekras\Atom\Element\Meta\HasCategories;

/**
* Category Document.
Expand All @@ -18,7 +18,7 @@
*/
class CategoryDocument extends Document
{
use Categories;
use HasCategories;

/**
* Indicating whether the list of categories is a fixed or an open set.
Expand Down
4 changes: 2 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[] = $this->getExtensions()->parseElement($item);
$workspaces[] = $this->getExtensions()->parseElement($this, $item);
}

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

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

$workspaces[] = $workspace;
Expand Down
4 changes: 2 additions & 2 deletions src/Element/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
namespace Mekras\AtomPub\Element;

use Mekras\Atom\Element\Meta\Title;
use Mekras\Atom\Element\Meta\HasTitle;

/**
* Collection.
Expand All @@ -18,7 +18,7 @@
*/
class Collection extends Element
{
use Title;
use HasTitle;

/**
* The IRI of the Collection.
Expand Down
2 changes: 1 addition & 1 deletion src/Element/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
*/
class Entry extends AtomEntry
{
use Meta\MemberUri;
use Meta\HasMemberUri;
}
60 changes: 0 additions & 60 deletions src/Element/Feed.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
namespace Mekras\AtomPub\Element\Meta;

use Mekras\Atom\Atom;
use Mekras\Atom\Element\Meta\Base;
use Mekras\Atom\Node;
use Mekras\Atom\NodeInterfaceTrait;

/**
* Support for "atom:link[rel=edit]".
Expand All @@ -18,9 +18,9 @@
*
* @link https://tools.ietf.org/html/rfc4287#section-9.1
*/
trait MemberUri
trait HasMemberUri
{
use Base;
use NodeInterfaceTrait;

/**
* Return Member URI.
Expand Down
8 changes: 4 additions & 4 deletions src/Element/Workspace.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
namespace Mekras\AtomPub\Element;

use Mekras\Atom\Element\Meta\Title;
use Mekras\Atom\Element\Meta\HasTitle;

/**
* Workspace.
Expand All @@ -18,7 +18,7 @@
*/
class Workspace extends Element
{
use Title;
use HasTitle;

/**
* Return collections.
Expand All @@ -38,7 +38,7 @@ function () {
/** @var \DOMNodeList $items */
$items = $this->query('app:collection');
foreach ($items as $item) {
$result[] = $this->getExtensions()->parseElement($item);
$result[] = $this->getExtensions()->parseElement($this, $item);
}

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

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

$collections[] = $collection;
Expand Down
56 changes: 34 additions & 22 deletions src/Extension/AtomPubExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Mekras\Atom\Element\Element;
use Mekras\Atom\Extension\DocumentExtension;
use Mekras\Atom\Extension\ElementExtension;
use Mekras\Atom\Extension\NamespaceExtension;
use Mekras\Atom\Extensions;
use Mekras\Atom\Node;
use Mekras\AtomPub\AtomPub;
Expand All @@ -27,7 +28,7 @@
*
* @since 1.0
*/
class AtomPubExtension implements DocumentExtension, ElementExtension
class AtomPubExtension implements DocumentExtension, ElementExtension, NamespaceExtension
{
/**
* Create Atom document from XML DOM document.
Expand Down Expand Up @@ -70,9 +71,9 @@ public function parseDocument(Extensions $extensions, \DOMDocument $document)
public function createDocument(Extensions $extensions, $name)
{
switch ($name) {
case 'service':
case 'app:service':
return new ServiceDocument($extensions);
case 'categories':
case 'app:categories':
return new CategoryDocument($extensions);
}

Expand All @@ -82,30 +83,30 @@ public function createDocument(Extensions $extensions, $name)
/**
* Create Atom node from XML DOM element.
*
* @param Extensions $extensions Extension registry.
* @param \DOMElement $element DOM element.
* @param Node $parent Parent node.
* @param \DOMElement $element DOM element.
*
* @return Element|null
*
* @throws \InvalidArgumentException
*
* @since 1.0
*/
public function parseElement(Extensions $extensions, $element)
public function parseElement(Node $parent, \DOMElement $element)
{
if (Atom::NS === $element->namespaceURI) {
switch ($element->localName) {
case 'entry':
return new Entry($extensions, $element);
return new Entry($parent, $element);
case 'feed':
return new Feed($extensions, $element);
return new Feed($parent, $element);
}
} elseif (AtomPub::NS === $element->namespaceURI) {
switch ($element->localName) {
case 'collection':
return new Collection($extensions, $element);
return new Collection($parent, $element);
case 'workspace':
return new Workspace($extensions, $element);
return new Workspace($parent, $element);
}
}

Expand All @@ -115,29 +116,40 @@ public function parseElement(Extensions $extensions, $element)
/**
* Create new Atom node.
*
* @param Extensions $extensions Extension registry.
* @param Node $parent Parent node.
* @param string $name Element name.
* @param Node $parent Parent node.
* @param string $name Element name.
*
* @return Element|null
*
* @throws \InvalidArgumentException
*
* @since 1.0
*/
public function createElement(Extensions $extensions, Node $parent, $name)
public function createElement(Node $parent, $name)
{
switch ($name) {
case 'entry':
return new Entry($extensions, $parent);
case 'feed':
return new Feed($extensions, $parent);
case 'collection':
return new Collection($extensions, $parent);
case 'workspace':
return new Workspace($extensions, $parent);
case 'atom:entry':
return new Entry($parent);
case 'atom:feed':
return new Feed($parent);
case 'app:collection':
return new Collection($parent);
case 'app:workspace':
return new Workspace($parent);
}

return null;
}

/**
* Return additional XML namespaces.
*
* @return string[] prefix => namespace.
*
* @since 1.0
*/
public function getNamespaces()
{
return [AtomPub::NS];
}
}
4 changes: 2 additions & 2 deletions tests/Element/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CollectionTest extends TestCase
public function testParse()
{
$collection = new Collection(
$this->createExtensions(),
$this->createFakeNode(),
$this->loadFixture('Collection.xml')->documentElement
);

Expand All @@ -43,7 +43,7 @@ public function testCreate()
'<collection xmlns="http://www.w3.org/2007/app" ' .
'xmlns:atom="http://www.w3.org/2005/Atom"/>'
);
$collection = new Collection($this->createExtensions(), $doc->documentElement);
$collection = new Collection($this->createFakeNode(), $doc->documentElement);
$collection->setTitle('Foo');
$collection->setHref('http://example.org/foo');
$collection->setAcceptedTypes(['a', 'b', 'c']);
Expand Down
6 changes: 3 additions & 3 deletions tests/Element/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class EntryTest extends TestCase
public function testGetMemberUri()
{
$entry = new Entry(
$this->createExtensions(),
$this->createFakeNode(),
$this->loadFixture('EntryDocument.xml')->documentElement
);
static::assertEquals('http://example.com/atom/atom/?edit=0001', $entry->getMemberUri());
Expand All @@ -33,7 +33,7 @@ public function testGetMemberUri()
public function testSetMemberUri1()
{
$entry = new Entry(
$this->createExtensions(),
$this->createFakeNode(),
$this->loadFixture('EntryDocument.xml')->documentElement
);
$entry->setMemberUri('http://example.com/atom/atom/?edit=0002');
Expand All @@ -50,7 +50,7 @@ public function testSetMemberUri1()
public function testSetMemberUri2()
{
$entry = new Entry(
$this->createExtensions(),
$this->createFakeNode(),
$this->loadFixture('EmptyEntry.xml')->documentElement
);
$entry->setMemberUri('http://example.com/atom/atom/?edit=0001');
Expand Down
46 changes: 0 additions & 46 deletions tests/Element/FeedTest.php

This file was deleted.

0 comments on commit 1563b83

Please sign in to comment.