Permalink
Browse files

Add a Log object rather than the old error behaviour

  • Loading branch information...
1 parent 48bd3b1 commit 5893ae03500dfac8a4cb4bfd10dea08c129ba1f8 @CloCkWeRX CloCkWeRX committed Dec 9, 2011
Showing with 15 additions and 11 deletions.
  1. +15 −11 XML/Feed/Parser/Factory.php
@@ -1,4 +1,6 @@
<?php
+require_once 'Log.php';
+require_once 'Log/null.php';
require_once 'XML/Feed/Parser/Sanitizer.php';
class XML_Feed_Parser_Factory {
@@ -12,6 +14,13 @@ class XML_Feed_Parser_Factory {
'http://backend.userland.com/rss2',
'http://blogs.law.harvard.edu/tech/rss'));
+ public function __construct(Log $log = null) {
+ if ($log === null) {
+ $log = new Log_null('', '', array(), null);
+ }
+ $this->log = $log;
+ }
+
/**
* Detects feed types and instantiate appropriate objects.
*
@@ -64,8 +73,6 @@ function build(DOMDocument $model, $feed, $strict = false, $suppressWarnings = f
public function determineClass($doc_element, $suppressWarnings = false)
{
- $error = false;
-
switch (true) {
case ($doc_element->namespaceURI == 'http://www.w3.org/2005/Atom'):
require_once 'XML/Feed/Parser/Atom.php';
@@ -76,8 +83,9 @@ public function determineClass($doc_element, $suppressWarnings = false)
require_once 'XML/Feed/Parser/Atom.php';
require_once 'XML/Feed/Parser/AtomElement.php';
$class = 'XML_Feed_Parser_Atom';
- $error = 'Atom 0.3 deprecated, using 1.0 parser which won\'t provide ' .
- 'all options';
+
+ $this->log->warning('Atom 0.3 deprecated, using 1.0 parser which won\'t provide ' .
+ 'all options');
break;
case ($doc_element->namespaceURI == 'http://purl.org/rss/1.0/' ||
($doc_element->hasChildNodes() && $doc_element->childNodes->length > 1
@@ -106,15 +114,15 @@ public function determineClass($doc_element, $suppressWarnings = false)
case ($doc_element->tagName == 'rss' and
$doc_element->hasAttribute('version') &&
$doc_element->getAttribute('version') == 0.91):
- $error = 'RSS 0.91 has been superceded by RSS2.0. Using RSS2.0 parser.';
+ $this->log->warning('RSS 0.91 has been superceded by RSS2.0. Using RSS2.0 parser.');
require_once 'XML/Feed/Parser/RSS2.php';
require_once 'XML/Feed/Parser/RSS2Element.php';
$class = 'XML_Feed_Parser_RSS2';
break;
case ($doc_element->tagName == 'rss' and
$doc_element->hasAttribute('version') &&
$doc_element->getAttribute('version') == 0.92):
- $error = 'RSS 0.92 has been superceded by RSS2.0. Using RSS2.0 parser.';
+ $this->log->warning('RSS 0.92 has been superceded by RSS2.0. Using RSS2.0 parser.');
require_once 'XML/Feed/Parser/RSS2.php';
require_once 'XML/Feed/Parser/RSS2Element.php';
$class = 'XML_Feed_Parser_RSS2';
@@ -123,7 +131,7 @@ public function determineClass($doc_element, $suppressWarnings = false)
|| $doc_element->tagName == 'rss'):
if (! $doc_element->hasAttribute('version') ||
$doc_element->getAttribute('version') != 2) {
- $error = 'RSS version not specified. Parsing as RSS2.0';
+ $this->log->warning('RSS version not specified. Parsing as RSS2.0');
}
require_once 'XML/Feed/Parser/RSS2.php';
require_once 'XML/Feed/Parser/RSS2Element.php';
@@ -134,10 +142,6 @@ public function determineClass($doc_element, $suppressWarnings = false)
break;
}
- if (! $suppressWarnings && ! empty($error)) {
- trigger_error($error, E_USER_WARNING);
- }
-
return $class;
}

0 comments on commit 5893ae0

Please sign in to comment.