Skip to content

Commit

Permalink
Add a Log object rather than the old error behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
CloCkWeRX committed Dec 9, 2011
1 parent 48bd3b1 commit 5893ae0
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions XML/Feed/Parser/Factory.php
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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.
*
Expand Down Expand Up @@ -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';
Expand All @@ -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
Expand Down Expand Up @@ -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';
Expand All @@ -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';
Expand All @@ -134,10 +142,6 @@ public function determineClass($doc_element, $suppressWarnings = false)
break;
}

if (! $suppressWarnings && ! empty($error)) {
trigger_error($error, E_USER_WARNING);
}


return $class;
}
Expand Down

0 comments on commit 5893ae0

Please sign in to comment.