Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Bug19 mirgration static to dynamic #23

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"require": {
"php": "^5.5 || ^7.0",
"zendframework/zend-escaper": "^2.5",
"zendframework/zend-stdlib": "^2.7 || ^3.0"
"zendframework/zend-stdlib": "^2.7 || ^3.0",
"psr/cache": "*"
},
"require-dev": {
"zendframework/zend-db": "^2.5",
Expand Down
26 changes: 22 additions & 4 deletions src/Reader/AbstractEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ abstract class AbstractEntry
*/
protected $data = [];

/**
* Feed Reader instance
*
* @var Reader\Reader
*/
protected $reader = null;

/**
* DOM document object
*
Expand Down Expand Up @@ -64,19 +71,30 @@ abstract class AbstractEntry
* @param int $entryKey
* @param null|string $type
*/
public function __construct(DOMElement $entry, $entryKey, $type = null)
public function __construct(Reader\Reader $reader, DOMElement $entry, $entryKey, $type = null)
{
$this->reader = $reader;
$this->entry = $entry;
$this->entryKey = $entryKey;
$this->domDocument = $entry->ownerDocument;
if ($type !== null) {
$this->data['type'] = $type;
} else {
$this->data['type'] = Reader::detectType($entry);
$this->data['type'] = $this->getReader()->detectType($entry);
}
$this->_loadExtensions();
}

/**
* Get Feed Reader
*
* @return Reader\Reader
*/
public function getReader()
{
return $this->reader;
}

/**
* Get the DOM
*
Expand Down Expand Up @@ -209,13 +227,13 @@ public function __call($method, $args)
*/
protected function _loadExtensions()
{
$all = Reader::getExtensions();
$all = $this->Reader()->getExtensions();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like get is missing here.

$feed = $all['entry'];
foreach ($feed as $extension) {
if (in_array($extension, $all['core'])) {
continue;
}
$className = Reader::getPluginLoader()->getClassName($extension);
$className = $this->getReader()->getPluginLoader()->getClassName($extension);
$this->extensions[$extension] = new $className(
$this->getElement(), $this->entryKey, $this->data['type']
);
Expand Down
27 changes: 23 additions & 4 deletions src/Reader/AbstractFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ abstract class AbstractFeed implements Feed\FeedInterface
*/
protected $data = [];

/**
* Feed Reader instance
*
* @var Reader\Reader
*/
protected $reader = null;

/**
* Parsed feed data in the shape of a DOMDocument
*
Expand Down Expand Up @@ -70,21 +77,32 @@ abstract class AbstractFeed implements Feed\FeedInterface
* @param DomDocument $domDocument The DOM object for the feed's XML
* @param string $type Feed type
*/
public function __construct(DOMDocument $domDocument, $type = null)
public function __construct(Reader\Reader $reader, DOMDocument $domDocument, $type = null)
{
$this->reader = $reader;
$this->domDocument = $domDocument;
$this->xpath = new DOMXPath($this->domDocument);

if ($type !== null) {
$this->data['type'] = $type;
} else {
$this->data['type'] = Reader::detectType($this->domDocument);
$this->data['type'] = $this->getReader()->detectType($this->domDocument);
}
$this->registerNamespaces();
$this->indexEntries();
$this->loadExtensions();
}

/**
* Get Feed Reader
*
* @return Reader\Reader
*/
public function getReader()
{
return $this->reader;
}

/**
* Set an original source URI for the feed being parsed. This value
* is returned from getFeedLink() method if the feed does not carry
Expand Down Expand Up @@ -271,14 +289,15 @@ public function getExtension($name)

protected function loadExtensions()
{
$all = Reader::getExtensions();
$manager = Reader::getExtensionManager();
$all = $this->getReader()->getExtensions();
$manager = $this->getReader()->getExtensionManager();
$feed = $all['feed'];
foreach ($feed as $extension) {
if (in_array($extension, $all['core'])) {
continue;
}
$plugin = $manager->get($extension);
$plugin->setReader($this->getReader());
$plugin->setDomDocument($this->getDomDocument());
$plugin->setType($this->data['type']);
$plugin->setXpath($this->xpath);
Expand Down
28 changes: 24 additions & 4 deletions src/Reader/Entry/AbstractEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ abstract class AbstractEntry
*/
protected $data = [];

/**
* Feed Reader instance
*
* @var Reader\Reader
*/
protected $reader = null;

/**
* DOM document object
*
Expand Down Expand Up @@ -66,21 +73,32 @@ abstract class AbstractEntry
* @param int $entryKey
* @param string $type
*/
public function __construct(DOMElement $entry, $entryKey, $type = null)
public function __construct(Reader\Reader $reader, DOMElement $entry, $entryKey, $type = null)
{
$this->reader = $reader;
$this->entry = $entry;
$this->entryKey = $entryKey;
$this->domDocument = $entry->ownerDocument;
if ($type !== null) {
$this->data['type'] = $type;
} elseif ($this->domDocument !== null) {
$this->data['type'] = Reader\Reader::detectType($this->domDocument);
$this->data['type'] = $this->getReader()->detectType($this->domDocument);
} else {
$this->data['type'] = Reader\Reader::TYPE_ANY;
}
$this->loadExtensions();
}

/**
* Get Feed Reader
*
* @return Reader\Reader
*/
public function getReader()
{
return $this->reader;
}

/**
* Get the DOM
*
Expand Down Expand Up @@ -216,14 +234,16 @@ public function __call($method, $args)
*/
protected function loadExtensions()
{
$all = Reader\Reader::getExtensions();
$manager = Reader\Reader::getExtensionManager();
$all = $this->getReader()->getExtensions();
$manager = $this->getReader()->getExtensionManager();

$feed = $all['entry'];
foreach ($feed as $extension) {
if (in_array($extension, $all['core'])) {
continue;
}
$plugin = $manager->get($extension);
$plugin->setReader($this->getReader());
$plugin->setEntryElement($this->getElement());
$plugin->setEntryKey($this->entryKey);
$plugin->setType($this->data['type']);
Expand Down
7 changes: 4 additions & 3 deletions src/Reader/Entry/Atom.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ class Atom extends AbstractEntry implements EntryInterface
* @param int $entryKey
* @param string $type
*/
public function __construct(DOMElement $entry, $entryKey, $type = null)
public function __construct(Reader\Reader $reader, DOMElement $entry, $entryKey, $type = null)
{
parent::__construct($entry, $entryKey, $type);
parent::__construct($reader, $entry, $entryKey, $type);

// Everyone by now should know XPath indices start from 1 not 0
$this->xpathQuery = '//atom:entry[' . ($this->entryKey + 1) . ']';

$manager = Reader\Reader::getExtensionManager();
$manager = $this->getReader()->getExtensionManager();
$extensions = ['Atom\Entry', 'Thread\Entry', 'DublinCore\Entry'];

foreach ($extensions as $name) {
$extension = $manager->get($name);
$extension->setReader($this->getReader());
$extension->setEntryElement($entry);
$extension->setEntryKey($entryKey);
$extension->setType($type);
Expand Down
9 changes: 5 additions & 4 deletions src/Reader/Entry/Rss.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class Rss extends AbstractEntry implements EntryInterface
* @param string $entryKey
* @param string $type
*/
public function __construct(DOMElement $entry, $entryKey, $type = null)
public function __construct(Reader\Reader $reader, DOMElement $entry, $entryKey, $type = null)
{
parent::__construct($entry, $entryKey, $type);
parent::__construct($reader, $entry, $entryKey, $type);
$this->xpathQueryRss = '//item[' . ($this->entryKey+1) . ']';
$this->xpathQueryRdf = '//rss:item[' . ($this->entryKey+1) . ']';

$manager = Reader\Reader::getExtensionManager();
$manager = $this->getReader()->getExtensionManager();
$extensions = [
'DublinCore\Entry',
'Content\Entry',
Expand All @@ -55,6 +55,7 @@ public function __construct(DOMElement $entry, $entryKey, $type = null)
];
foreach ($extensions as $name) {
$extension = $manager->get($name);
$extension->setReader($this->getReader());
$extension->setEntryElement($entry);
$extension->setEntryKey($entryKey);
$extension->setType($type);
Expand Down Expand Up @@ -125,7 +126,7 @@ public function getAuthors()
$authors = $this->getExtension('Atom')->getAuthors();
} else {
$authors = new Reader\Collection\Author(
Reader\Reader::arrayUnique($authors)
$this->getReader()->arrayUnique($authors)
);
}

Expand Down
29 changes: 28 additions & 1 deletion src/Reader/Extension/AbstractEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,33 @@ abstract class AbstractEntry
*/
protected $xpathPrefix = '';

/**
* Feed Reader instance
*
* @var Reader
*/
protected $reader = null;

/**
* Set the entry Feed Reader
*
* @param Reader\Reader $reader
*/
public function setReader(Reader\Reader $reader)
{
$this->reader = $reader;
}

/**
* Get Feed Reader
*
* @return Reader\Reader
*/
public function getReader()
{
return $this->reader;
}

/**
* Set the entry DOMElement
*
Expand Down Expand Up @@ -159,7 +186,7 @@ public function getType()
{
$type = $this->data['type'];
if ($type === null) {
$type = Reader\Reader::detectType($this->getEntryElement(), true);
$type = $this->getReader()->detectType($this->getEntryElement(), true);
$this->setType($type);
}

Expand Down
29 changes: 28 additions & 1 deletion src/Reader/Extension/AbstractFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,33 @@ abstract class AbstractFeed
*/
protected $xpathPrefix = '';

/**
* Feed Reader instance
*
* @var Reader
*/
protected $reader = null;

/**
* Set the entry Feed Reader
*
* @param Reader\Reader $reader
*/
public function setReader(Reader\Reader $reader)
{
$this->reader = $reader;
}

/**
* Get Feed Reader
*
* @return Reader\Reader
*/
public function getReader()
{
return $this->reader;
}

/**
* Set the DOM document
*
Expand Down Expand Up @@ -99,7 +126,7 @@ public function getType()
{
$type = $this->data['type'];
if (null === $type) {
$type = Reader\Reader::detectType($this->getDomDocument());
$type = $this->getReader()->detectType($this->getDomDocument());
$this->setType($type);
}
return $type;
Expand Down
4 changes: 2 additions & 2 deletions src/Reader/Extension/Atom/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function getAuthors()
$authors = new Collection\Author();
} else {
$authors = new Collection\Author(
Reader\Reader::arrayUnique($authors)
$this->getReader()->arrayUnique($authors)
);
}

Expand Down Expand Up @@ -537,7 +537,7 @@ public function getSource()
$list = $this->getXpath()->query($this->getXpathPrefix() . '/atom:source[1]');
if ($list->length) {
$element = $list->item(0);
$source = new Reader\Feed\Atom\Source($element, $this->getXpathPrefix());
$source = new Reader\Feed\Atom\Source($this->getReader(), $element, $this->getXpathPrefix());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Reader/Extension/Atom/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getAuthors()
$authors = new Collection\Author();
} else {
$authors = new Collection\Author(
Reader\Reader::arrayUnique($authors)
$this->getReader()->arrayUnique($authors)
);
}

Expand Down
3 changes: 1 addition & 2 deletions src/Reader/Extension/DublinCore/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
namespace Zend\Feed\Reader\Extension\DublinCore;

use DateTime;
use Zend\Feed\Reader;
use Zend\Feed\Reader\Collection;
use Zend\Feed\Reader\Extension;

Expand Down Expand Up @@ -65,7 +64,7 @@ public function getAuthors()
];
}
$authors = new Collection\Author(
Reader\Reader::arrayUnique($authors)
$this->getReader()->arrayUnique($authors)
);
} else {
$authors = null;
Expand Down
Loading