Skip to content

Commit

Permalink
Disabled strange libxml error_reporting, added libxml options
Browse files Browse the repository at this point in the history
  • Loading branch information
SpazzMarticus committed Sep 18, 2015
1 parent c745224 commit 531f8c9
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/eCSStractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
*/
class eCSStractor
{
protected $_libxmlOptions=0;

/**
* Returns the Libxml-Option-Setting used when parsing the HTML string
* @return int
*/
public function getLibxmlOptions()
{
return $this->_libxmlOptions;
}

/**
* Sets the Libxml-Option-Setting used when parsing the HTML string
* @link http://php.net/manual/en/libxml.constants.php
* @param int $libxmlOptions
* @return \SpazzMarticus\eCSStractor\eCSStractor
*/
public function setLibxmlOptions($libxmlOptions)
{
$this->_libxmlOptions=$libxmlOptions;
return $this;
}

/**
* Extracts all CSS found in Style-Tags in the given HTML and returns it
Expand All @@ -22,8 +44,15 @@ class eCSStractor
*/
public function extract($html)
{
$errorHandling=libxml_use_internal_errors(true);

$doc=new DOMDocument();
$doc->loadHTML($html);
$htmlLoaded=$doc->loadHTML($html, $this->_libxmlOptions);

if (!$htmlLoaded)
{
throw new \InvalidArgumentException('The HTML-Document given could not be parsed!', 1);
}

$stylesheet='';

Expand All @@ -35,6 +64,7 @@ public function extract($html)
$stylesheet.=$styleTag->textContent;
}

libxml_use_internal_errors($errorHandling);
return $stylesheet;
}
}

0 comments on commit 531f8c9

Please sign in to comment.