Skip to content

Commit

Permalink
Bugfix for custom elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddebin committed Sep 13, 2019
1 parent 8182ce0 commit 2623615
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
12 changes: 6 additions & 6 deletions src/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,18 @@ public function getEntries(): array

/**
* @param string $ns
* @param string $url
* @param string $uri
* @param string $name
* @param mixed $value
* @param null|string[] $attributes
*/
public function addCustomElement(string $ns, string $url, string $name, $value, ?array $attributes = null): void
public function addCustomElement(string $ns, string $uri, string $name, $value, ?array $attributes = null): void
{
self::assertURL($url);
self::assertURL($uri);

$this->customElements[] = [
'ns' => $ns,
'url' => $url,
'uri' => $uri,
'name' => $name,
'value' => $value,
'attributes' => $attributes ?? [],
Expand Down Expand Up @@ -186,7 +186,7 @@ public function addChildrenTo(SimpleXMLElement $parent): void
}

foreach ($this->customElements as $customElement) {
$element = $parent->addChild($customElement['name'], $customElement['value'], $customElement['ns']);
$element = $parent->addChild($customElement['name'], $customElement['value'], $customElement['uri']);
foreach ($customElement['attributes'] as $name => $value) {
$element->addAttribute($name, $value);
}
Expand All @@ -207,7 +207,7 @@ public function getSimpleXML(): SimpleXMLElement
$attributes['xml:lang'] = $this->language;
}
foreach ($this->customElements as $customElement) {
$attributes['xmlns:'.$customElement['ns']] = $customElement['url'];
$attributes['xmlns:'.$customElement['ns']] = $customElement['uri'];
}

$attributesString = '';
Expand Down
2 changes: 1 addition & 1 deletion tests/FeedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function testFeedCreation1(): void
$feed->addContributor('contributor', '[email protected]', 'http://test.com/contributor');
$feed->setUpdatedDateTime(new DateTime('2019-05-04T20:00:40Z'));
$feed->addCustomElement('sy', 'http://purl.org/rss/1.0/modules/syndication', 'updatePeriod', 'hourly');
$feed->addCustomElement('sy', 'http://purl.org/rss/1.0/modules/syndication', 'sy:updateFrequency', 10);
$feed->addCustomElement('sy', 'http://purl.org/rss/1.0/modules/syndication', 'updateFrequency', 10);

$entry = new Entry();
$entry->setTitle('entry title', 'text');
Expand Down
4 changes: 2 additions & 2 deletions tests/feed_1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
<logo>http://test.com/logo</logo>
<icon>http://test.com/icon</icon>
<generator version="version" uri="http://test.com/generator">generator</generator>
<updatePeriod xmlns="sy">hourly</updatePeriod>
<sy:updateFrequency xmlns:sy="sy">10</sy:updateFrequency>
<sy:updatePeriod>hourly</sy:updatePeriod>
<sy:updateFrequency>10</sy:updateFrequency>
<entry>
<id>tag:entry-test</id>
<title type="text">entry title</title>
Expand Down

0 comments on commit 2623615

Please sign in to comment.