From a58f74f3b9350d2a546e09a324203246c436ea47 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Fri, 9 Dec 2011 23:54:59 +1030 Subject: [PATCH] Remove itemClass usage from most places --- XML/Feed/Parser/Atom.php | 3 ++- XML/Feed/Parser/RSS09.php | 3 +-- XML/Feed/Parser/RSS1.php | 3 +-- XML/Feed/Parser/RSS11.php | 7 +++---- XML/Feed/Parser/RSS2.php | 3 +-- XML/Feed/Parser/Type.php | 2 ++ 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/XML/Feed/Parser/Atom.php b/XML/Feed/Parser/Atom.php index 2842d01..4d1610d 100644 --- a/XML/Feed/Parser/Atom.php +++ b/XML/Feed/Parser/Atom.php @@ -150,7 +150,8 @@ function getEntryById($id) if ($entries->length > 0) { $xmlBase = $entries->item(0)->baseURI; /** @todo Avoid instantiating classes we can't keep track of */ - $entry = new $this->itemClass($entries->item(0), $this, $xmlBase); + $entry = new XML_Feed_Parser_AtomElement($entries->item(0), $this, $xmlBase); + $entry->setSanitizer($this->getSanitizer()); if (in_array('evaluate', get_class_methods($this->xpath))) { $offset = $this->xpath->evaluate("count(preceding-sibling::atom:entry)", $entries->item(0)); diff --git a/XML/Feed/Parser/RSS09.php b/XML/Feed/Parser/RSS09.php index 7c7461f..69d9cf8 100644 --- a/XML/Feed/Parser/RSS09.php +++ b/XML/Feed/Parser/RSS09.php @@ -105,13 +105,12 @@ class XML_Feed_Parser_RSS09 extends XML_Feed_Parser_Type function __construct(DOMDocument $model, $strict = false) { $this->model = $model; - + $this->setSanitizer(new XML_Feed_Parser_Unsafe_Sanitizer()); $this->xpath = new DOMXPath($model); foreach ($this->namespaces as $key => $value) { $this->xpath->registerNamespace($key, $value); } $this->numberEntries = $this->count('item'); - $this->setSanitizer(new XML_Feed_Parser_Unsafe_Sanitizer()); } /** diff --git a/XML/Feed/Parser/RSS1.php b/XML/Feed/Parser/RSS1.php index 628125c..6c4984e 100644 --- a/XML/Feed/Parser/RSS1.php +++ b/XML/Feed/Parser/RSS1.php @@ -155,8 +155,7 @@ function getEntryById($id) $entries = $this->xpath->query("//rss:item[@rdf:about='$id']"); if ($entries->length > 0) { - $classname = $this->itemClass; - $entry = new $classname($entries->item(0), $this); + $entry = new XML_Feed_Parser_RSS1Element($entries->item(0), $this); if (in_array('evaluate', get_class_methods($this->xpath))) { $offset = $this->xpath->evaluate("count(preceding-sibling::rss:item)", $entries->item(0)); $this->entries[$offset] = $entry; diff --git a/XML/Feed/Parser/RSS11.php b/XML/Feed/Parser/RSS11.php index e2c1d91..b4678f6 100644 --- a/XML/Feed/Parser/RSS11.php +++ b/XML/Feed/Parser/RSS11.php @@ -121,7 +121,7 @@ class XML_Feed_Parser_RSS11 extends XML_Feed_Parser_Type function __construct(DOMDocument $model, $strict = false) { $this->model = $model; - + $this->setSanitizer(new XML_Feed_Parser_Unsafe_Sanitizer()); if ($strict) { if (! $this->relaxNGValidate()) { throw new XML_Feed_Parser_Exception('Failed required validation'); @@ -133,7 +133,7 @@ function __construct(DOMDocument $model, $strict = false) $this->xpath->registerNamespace($key, $value); } $this->numberEntries = $this->count('item'); - $this->setSanitizer(new XML_Feed_Parser_Unsafe_Sanitizer()); + } /** @@ -156,8 +156,7 @@ function getEntryById($id) $entries = $this->xpath->query("//rss:item[@rdf:about='$id']"); if ($entries->length > 0) { - $classname = $this->itemClass; - $entry = new $classname($entries->item(0), $this); + $entry = new XML_Feed_Parser_RSS1Element($entries->item(0), $this); return $entry; } return false; diff --git a/XML/Feed/Parser/RSS2.php b/XML/Feed/Parser/RSS2.php index fc029f2..d1aee41 100644 --- a/XML/Feed/Parser/RSS2.php +++ b/XML/Feed/Parser/RSS2.php @@ -114,7 +114,7 @@ class XML_Feed_Parser_RSS2 extends XML_Feed_Parser_Type function __construct(DOMDocument $model, $strict = false) { $this->model = $model; - + $this->setSanitizer(new XML_Feed_Parser_Unsafe_Sanitizer()); if ($strict) { if (! $this->relaxNGValidate()) { throw new XML_Feed_Parser_Exception('Failed required validation'); @@ -126,7 +126,6 @@ function __construct(DOMDocument $model, $strict = false) $this->xpath->registerNamespace($key, $value); } $this->numberEntries = $this->count('item'); - $this->setSanitizer(new XML_Feed_Parser_Unsafe_Sanitizer()); } /** diff --git a/XML/Feed/Parser/Type.php b/XML/Feed/Parser/Type.php index 3bd3c89..c1462a3 100644 --- a/XML/Feed/Parser/Type.php +++ b/XML/Feed/Parser/Type.php @@ -210,6 +210,8 @@ function getEntryByOffset($offset) $entries = $this->model->getElementsByTagName($this->itemElement); if ($entries->length > $offset) { $xmlBase = $entries->item($offset)->baseURI; + /** @todo Remove this behaviour - each driver should control this better */ + /** @todo Try to avoid new here */ $this->entries[$offset] = new $this->itemClass( $entries->item($offset), $this, $xmlBase); if ($id = $this->entries[$offset]->id) {