package.xml 0000664 0001750 0001750 00000010651 12531446143 013063 0 ustar theseer theseer
fDOMDocumentpear.netpirates.netAn Extension to PHP's standard DOM to add various convenience methods and exceptions by defaultAn Extension to PHP's standard DOM to add various convenience methods and exceptions by default.Arne Blankertstheseerarne@blankerts.deyes2015-05-271.6.11.6.0stablestableBSD License
http://github.com/theseer/fDOMDocument/tree
5.3.31.9.1libxmldom
fDOMDocument-1.6.1/TheSeer/fDOMDocument/css/DollarEqualRule.php 0000664 0001750 0001750 00000001405 12531446143 024051 0 ustar theseer theseer translator = $translator;
}
/**
* @param $selector
*
* @return string
*/
public function apply($selector) {
return preg_replace_callback(
'/([a-zA-Z0-9\_\-\*]+):not\(([^\)]*)\)/',
array($this, 'callback'),
$selector
);
}
/**
* @param array $matches
*
* @return string
*/
private function callback(array $matches) {
$subresult = preg_replace(
'/^[^\[]+\[([^\]]*)\].*$/',
'$1',
$this->translator->translate($matches[2])
);
return $matches[1] . '[not(' . $subresult . ')]';
}
}
}
fDOMDocument-1.6.1/TheSeer/fDOMDocument/css/NthChildRule.php 0000664 0001750 0001750 00000002711 12531446143 023342 0 ustar theseer theseer =0]/self::' . $matches[1];
}
case 'odd': {
return $matches[1] . '[(count(preceding-sibling::*) + 1) mod 2=1]';
}
default: {
$b = !isset($matches[2]) || empty($matches[2]) ? '0' : $matches[2];
$b = preg_replace('/^([0-9]*)n.*?([0-9]*)$/', '$1+$2', $b);
$b = explode('+', $b);
if (!isset($b[1])) {
$b[1] = '0';
}
return '*[(position()-' . $b[1] . ') mod ' . $b[0] . '=0 and position()>=' . $b[1] . ']/self::' . $matches[1];
}
}
}
}
}
fDOMDocument-1.6.1/TheSeer/fDOMDocument/css/RegexRule.php 0000664 0001750 0001750 00000001307 12531446143 022717 0 ustar theseer theseer regex = $regex;
$this->replacement = $replacement;
}
/**
* @param $selector
*
* @return string
*/
public function apply($selector) {
return preg_replace($this->regex, $this->replacement, $selector);
}
}
}
fDOMDocument-1.6.1/TheSeer/fDOMDocument/css/RuleInterface.php 0000664 0001750 0001750 00000000320 12531446143 023537 0 ustar theseer theseer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Arne Blankerts nor the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER ORCONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @copyright Arne Blankerts , All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://github.com/theseer/fdomdocument
*
*/
namespace TheSeer\fDOM\CSS {
/**
* Class Translator
*
* The regular expressions used in this class are heavily inspired by and mostly adopted from
* the css2xpath.js code by Andrea Giammarchi (http://code.google.com/p/css2xpath/).
* The JavaScript version (css2xpath.js) is licensed under the MIT License
*
*/
class Translator {
/**
* @var array
*/
private $rules;
/**
* @param string $selector A CSS Selector string
*
* @return string
*/
public function translate($selector) {
foreach($this->getRules() as $rule) {
/** @var RuleInterface $rule */
$selector = $rule->apply($selector);
}
return '//' . $selector;
}
/**
* @return array
*/
private function getRules() {
if ($this->rules != NULL) {
return $this->rules;
}
$this->rules = array(
// prefix|name
new RegexRule('/([a-zA-Z0-9\_\-\*]+)\|([a-zA-Z0-9\_\-\*]+)/', '$1:$2'),
// add @ for attribs
new RegexRule("/\[([^\]~\$\*\^\|\!]+)(=[^\]]+)?\]/", '[@$1$2]'),
// multiple queries
new RegexRule("/\s*,\s*/", '|'),
// , + ~ >
new RegexRule("/\s*(\+|~|>)\s*/", '$1'),
//* ~ + >
new RegexRule("/([a-zA-Z0-9\_\-\*])~([a-zA-Z0-9\_\-\*])/", '$1/following-sibling::$2'),
new RegexRule("/([a-zA-Z0-9\_\-\*])\+([a-zA-Z0-9\_\-\*])/", '$1/following-sibling::*[1]/self::$2'),
new RegexRule("/([a-zA-Z0-9\_\-\*])>([a-zA-Z0-9\_\-\*])/", '$1/$2'),
// all unescaped stuff escaped
new RegexRule("/\[([^=]+)=([^'|'][^\]]*)\]/", '[$1="$2"]'),
// all descendant or self to //
new RegexRule("/(^|[^a-zA-Z0-9\_\-\*])(#|\.)([a-zA-Z0-9\_\-]+)/", '$1*$2$3'),
new RegexRule("/([\>\+\|\~\,\s])([a-zA-Z\*]+)/", '$1//$2'),
new RegexRule("/\s+\/\//", '//'),
// :first-child
new RegexRule("/([a-zA-Z0-9\_\-\*]+):first-child/", '*[1]/self::$1'),
// :last-child
new RegexRule("/([a-zA-Z0-9\_\-\*]+):last-child/", '$1[not(following-sibling::*)]'),
// :only-child
new RegexRule("/([a-zA-Z0-9\_\-\*]+):only-child/", '*[last()=1]/self::$1'),
// :empty
new RegexRule("/([a-zA-Z0-9\_\-\*]+):empty/", '$1[not(*) and not(normalize-space())]'),
// :not
new NotRule($this),
// :nth-child
new NthChildRule(),
// :contains(selectors)
new RegexRule('/:contains\(([^\)]*)\)/', '[contains(string(.),"$1")]'),
// |= attrib
new RegexRule("/\[([a-zA-Z0-9\_\-]+)\|=([^\]]+)\]/", '[@$1=$2 or starts-with(@$1,concat($2,"-"))]'),
// *= attrib
new RegexRule("/\[([a-zA-Z0-9\_\-]+)\*=([^\]]+)\]/", '[contains(@$1,$2)]'),
// ~= attrib
new RegexRule("/\[([a-zA-Z0-9\_\-]+)~=([^\]]+)\]/", '[contains(concat(" ",normalize-space(@$1)," "),concat(" ",$2," "))]'),
// ^= attrib
new RegexRule("/\[([a-zA-Z0-9\_\-]+)\^=([^\]]+)\]/", '[starts-with(@$1,$2)]'),
// $= attrib
new DollarEqualRule(),
// != attrib
new RegexRule("/\[([a-zA-Z0-9\_\-]+)\!=([^\]]+)\]/", '[not(@$1) or @$1!=$2]'),
// ids and classes
new RegexRule("/#([a-zA-Z0-9\_\-]+)/", '[@id="$1"]'),
new RegexRule("/\.([a-zA-Z0-9\_\-]+)/", '[contains(concat(" ",normalize-space(@class)," ")," $1 ")]'),
// normalize multiple filters
new RegexRule("/\]\[([^\]]+)/", ' and ($1)')
);
return $this->rules;
}
}
}
fDOMDocument-1.6.1/TheSeer/fDOMDocument/autoload.php 0000664 0001750 0001750 00000002676 12531446143 022047 0 ustar theseer theseer '/css/DollarEqualRule.php',
'theseer\\fdom\\css\\notrule' => '/css/NotRule.php',
'theseer\\fdom\\css\\nthchildrule' => '/css/NthChildRule.php',
'theseer\\fdom\\css\\regexrule' => '/css/RegexRule.php',
'theseer\\fdom\\css\\ruleinterface' => '/css/RuleInterface.php',
'theseer\\fdom\\css\\translator' => '/css/Translator.php',
'theseer\\fdom\\fdomdocument' => '/fDOMDocument.php',
'theseer\\fdom\\fdomdocumentfragment' => '/fDOMDocumentFragment.php',
'theseer\\fdom\\fdomelement' => '/fDOMElement.php',
'theseer\\fdom\\fdomexception' => '/fDOMException.php',
'theseer\\fdom\\fdomnode' => '/fDOMNode.php',
'theseer\\fdom\\fdomxpath' => '/fDOMXPath.php',
'theseer\\fdom\\xpathquery' => '/XPathQuery.php',
'theseer\\fdom\\xpathqueryexception' => '/XPathQueryException.php'
);
}
$cn = strtolower($class);
if (isset($classes[$cn])) {
require __DIR__ . $classes[$cn];
}
}
);
// @codeCoverageIgnoreEnd
fDOMDocument-1.6.1/TheSeer/fDOMDocument/fDOMDocumentFragment.php 0000664 0001750 0001750 00000015313 12531446143 024177 0 ustar theseer theseer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Arne Blankerts nor the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER ORCONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @copyright Arne Blankerts , All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://github.com/theseer/fdomdocument
*
*/
namespace TheSeer\fDOM {
/**
* fDOMDocumentFragment
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @access public
* @property fDOMDocument $ownerDocument
*
*/
class fDOMDocumentFragment extends \DOMDocumentFragment {
/**
* @return string
*/
public function __toString() {
return $this->ownerDocument->saveXML($this);
}
/**
* Wrapper to standard method with exception support
*
* @param string $str Data string to parse and append
*
* @throws fDOMException
*
* @return bool true on success
*/
public function appendXML($str) {
if (!parent::appendXML($str)) {
throw new fDOMException('Appending xml string failed', fDOMException::ParseError);
}
return true;
}
/**
* Create a new element and append it
*
* @param string $name Name of not element to create
* @param string $content Optional content to be set
*
* @return fDOMElement Reference to created fDOMElement
*/
public function appendElement($name, $content = null) {
$node = $this->ownerDocument->createElement($name, $content);
$this->appendChild($node);
return $node;
}
/**
* Create a new element in given namespace and append it
*
* @param string $ns Namespace of node to create
* @param string $name Name of not element to create
* @param string $content Optional content to be set
*
* @return fDOMElement Reference to created fDOMElement
*/
public function appendElementNS($ns, $name, $content = null) {
$node = $this->ownerDocument->createElementNS($ns, $name, $content);
$this->appendChild($node);
return $node;
}
/**
* Create a new element in given namespace and append it
*
* @param string $prefix Namespace prefix for node to create
* @param string $name Name of not element to create
* @param string $content Optional content to be set
*
* @return fDOMElement Reference to created fDOMElement
*/
public function appendElementPrefix($prefix, $name, $content = null) {
$node = $this->ownerDocument->createElementPrefix($prefix, $name, $content);
$this->appendChild($node);
return $node;
}
/**
* Create a new text node and append it
*
* @param string $content Text content to be added
*
* @return \DOMText
*/
public function appendTextNode($content) {
$text = $this->ownerDocument->createTextNode($content);
$this->appendChild($text);
return $text;
}
/**
* Check if the given node is in the same document
*
* @param \DOMNode $node Node to compare with
*
* @return boolean true on match, false if they differ
*
*/
public function inSameDocument(\DOMNode $node) {
return $this->ownerDocument->inSameDocument($node);
}
/**
* Forward to fDomDocument->query()
*
* @param string $q XPath to use
* @param \DOMNode $ctx \DOMNode to overwrite context
* @param boolean $registerNodeNS Register flag pass thru
*
* @return \DomNodeList
*/
public function query($q, \DOMNode $ctx = null, $registerNodeNS = true) {
return $this->ownerDocument->query($q, $ctx ? $ctx : $this, $registerNodeNS);
}
/**
* Forward to fDomDocument->queryOne()
*
* @param string $q XPath to use
* @param \DOMNode $ctx (optional) \DOMNode to overwrite context
* @param boolean $registerNodeNS Register flag pass thru
*
* @return mixed
*/
public function queryOne($q, \DOMNode $ctx = null, $registerNodeNS = true) {
return $this->ownerDocument->queryOne($q, $ctx ? $ctx : $this, $registerNodeNS);
}
/**
* Forward to fDomDocument->select()
*
* @param string $selector A CSS Level 3 Selector string
* @param \DOMNode $ctx
* @param bool $registerNodeNS
*
* @return \DOMNodeList
*/
public function select($selector, \DOMNode $ctx = null, $registerNodeNS = true) {
return $this->ownerDocument->select($selector, $ctx ? $ctx : $this, $registerNodeNS);
}
} // fDOMDocumentFragment
}
fDOMDocument-1.6.1/TheSeer/fDOMDocument/fDOMDocument.php 0000664 0001750 0001750 00000054326 12531446143 022522 0 ustar theseer theseer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Arne Blankerts nor the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER ORCONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @copyright Arne Blankerts , All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://github.com/theseer/fdomdocument
*
*/
namespace TheSeer\fDOM {
use TheSeer\fDOM\CSS\Translator;
/**
* fDOMDocument extension to PHP's DOMDocument.
* This class adds various convenience methods to simplify APIs
* It is set to final since further extending it would even more
* break the Object structure after use of registerNodeClass.
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @access public
* @property fDOMDocument $ownerDocument
*
*/
class fDOMDocument extends \DOMDocument {
/**
* XPath Object instance
*
* @var fDOMXPath
*/
private $xp = NULL;
/**
* List of registered prefixes and their namespace uri
* @var Array
*/
private $prefixes = array();
/**
* Extended DOMDocument constructor
*
* @param string $version XML Version, should be 1.0
* @param string $encoding Encoding, defaults to utf-8
* @param array $streamOptions optional stream options array
*
* @return fDOMDocument
*/
public function __construct($version = '1.0', $encoding = 'utf-8', $streamOptions = NULL) {
if (!is_null($streamOptions)) {
$this->setStreamContext($streamOptions);
}
libxml_use_internal_errors(TRUE);
$rc = parent::__construct($version, $encoding);
$this->registerNodeClasses();
return $rc;
}
/**
* Reset XPath object so the clone gets a new instance when needed
*/
public function __clone() {
$this->registerNodeClasses();
$this->xp = new fDOMXPath($this);
foreach($this->prefixes as $prefix => $uri) {
$this->xp->registerNamespace($prefix, $uri);
}
}
/**
* @return string
*/
public function __toString() {
return $this->C14N();
}
/**
* Set Stream context options
*
* @param Array $options Stream context options
*
* @return boolean true on success, false on failure
*/
public function setStreamContext(Array $options) {
if (!count($options)) {
return FALSE;
}
$context = stream_context_create($options);
libxml_set_streams_context($context);
return TRUE;
}
/**
* Wrapper to DOMDocument load with exception handling
* Returns true on success to satisfy the compatibilty of the original DOM Api
*
* @param string $fname File to load
* @param int|null $options LibXML Flags to pass
*
* @throws fDOMException
*
* @return bool|mixed
*/
public function load($fname, $options = LIBXML_NONET) {
$this->xp = NULL;
$tmp = parent :: load($fname, $options);
if (!$tmp || libxml_get_last_error()) {
throw new fDOMException("loading file '$fname' failed.", fDOMException::LoadError);
}
$this->registerNodeClasses();
return TRUE;
}
/**
* Wrapper to DOMDocument loadXML with exception handling
* Returns true on success to satisfy the compatibilty of the original DOM Api
*
* @param string $source XML source code
* @param integer $options LibXML option flags
*
* @throws fDOMException
*
* @return boolean
*/
public function loadXML($source, $options = LIBXML_NONET) {
$this->xp = NULL;
$tmp = parent :: loadXML($source, $options);
if (!$tmp || libxml_get_last_error()) {
throw new fDOMException('parsing string failed', fDOMException::ParseError);
}
$this->registerNodeClasses();
return TRUE;
}
/**
* Wrapper to DOMDocument loadHTMLFile with exception handling.
* Returns true on success to satisfy the compatibilty of the original DOM Api
*
* @param string $fname html file to load
* @param integer $options Options bitmask (@see DOMDocument::loadHTMLFile)
*
* @throws fDOMException
*
* @return boolean
*/
public function loadHTMLFile($fname, $options = NULL) {
$this->xp = NULL;
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
if ($options != NULL) {
throw new fDOMException('Passing options requires PHP 5.4.0+', fDOMException::LoadError);
}
$tmp = parent :: loadHTMLFile($fname);
} else {
$tmp = parent :: loadHTMLFile($fname, $options);
}
if (!$tmp || libxml_get_last_error()) {
throw new fDOMException("loading html file '$fname' failed", fDOMException::LoadError);
}
$this->registerNodeClasses();
return TRUE;
}
/**
* Wrapper to DOMDocument loadHTML with exception handling
* Returns true on success to satisfy the compatibilty of the original DOM Api
*
* @param string $source html source code
* @param integer $options Options bitmask (@see DOMDocument::loadHTML)
*
* @throws fDOMException
*
* @return boolean
*/
public function loadHTML($source, $options = NULL) {
$this->xp = NULL;
if (version_compare(PHP_VERSION, '5.4.0', '<')) {
if ($options != NULL) {
throw new fDOMException('Passing options requires PHP 5.4.0+', fDOMException::LoadError);
}
$tmp = parent :: loadHTML($source);
} else {
$tmp = parent :: loadHTML($source, $options);
}
if (!$tmp || libxml_get_last_error()) {
throw new fDOMException('parsing html string failed', fDOMException::ParseError);
}
$this->registerNodeClasses();
return TRUE;
}
/**
* Wrapper to DOMDocument::save with exception handling
*
* @param string $filename filename to save to
* @param integer $options Options bitmask (@see DOMDocument::save)
*
* @throws fDOMException
*
* @return integer bytes saved
*/
public function save($filename, $options = NULL) {
$tmp = parent::save($filename, $options);
if (!$tmp) {
throw new fDOMException("Saving XML to file '$filename' failed", fDOMException::SaveError);
}
return $tmp;
}
/**
* Wrapper to DOMDocument::saveHTML with exception handling
*
* @param \DOMNode|null $node Context DOMNode (optional)
*
* @throws fDOMException
*
* @return string html content
*/
public function saveHTML(\DOMNode $node = NULL) {
if (version_compare(PHP_VERSION, '5.3.6', '<') && $node != NULL) {
throw new fDOMException('Passing a context node requires PHP 5.3.6+', fDOMException::SaveError);
}
$tmp = parent::saveHTML($node);
if (!$tmp) {
throw new fDOMException('Serializing to HTML failed', fDOMException::SaveError);
}
return $tmp;
}
/**
* Wrapper to DOMDocument::saveHTMLfile with exception handling
*
* @param string $filename filename to save to
* @param integer $options Options bitmask (@see DOMDocument::saveHTMLFile)
*
* @throws fDOMException
*
* @return integer bytes saved
*/
public function saveHTMLFile($filename, $options = NULL) {
$tmp = parent::saveHTMLFile($filename, $options);
if (!$tmp) {
throw new fDOMException("Saving HTML to file '$filename' failed", fDOMException::SaveError);
}
return $tmp;
}
/**
* Wrapper to DOMDocument::saveXML with exception handling
*
* @param \DOMNode $node node to start serializing at
* @param integer $options options flags as bitmask
*
* @throws fDOMException
*
* @return string serialized XML
*/
public function saveXML(\DOMNode $node = NULL, $options = NULL) {
try {
$tmp = parent::saveXML($node, $options);
if (!$tmp) {
throw new fDOMException('Serializing to XML failed', fDOMException::SaveError);
}
return $tmp;
} catch (\Exception $e) {
if (!$e instanceof fDOMException) {
throw new fDOMException($e->getMessage(), fDOMException::SaveError, $e);
}
throw $e;
}
}
/**
* get Instance of DOMXPath Object for current DOM
*
* @throws fDOMException
*
* @return fDOMXPath
*/
public function getDOMXPath() {
if (is_null($this->xp)) {
$this->xp = new fDOMXPath($this);
}
if (!$this->xp) {
throw new fDOMException('creating DOMXPath object failed.', fDOMException::NoDOMXPath);
}
return $this->xp;
}
/**
* Convert a given DOMNodeList into a DOMFragment
*
* @param \DOMNodeList $list The Nodelist to process
* @param boolean $move Signale if nodes are to be moved into fragment or not
*
* @return fDOMDocumentFragment
*/
public function nodeList2Fragment(\DOMNodeList $list, $move=FALSE) {
$frag = $this->createDocumentFragment();
/** @var fDOMNode $node */
foreach($list as $node) {
$frag->appendChild($move ? $node : $node->cloneNode(TRUE));
}
return $this->ensureIntance($frag);
}
/**
* Perform an xpath query
*
* @param String $q query string containing xpath
* @param \DOMNode|null $ctx (optional) Context DOMNode
* @param boolean $registerNodeNS Register flag pass through
*
* @return \DOMNodeList
*/
public function query($q, \DOMNode $ctx = NULL, $registerNodeNS = TRUE) {
if (is_null($this->xp)) {
$this->getDOMXPath();
}
return $this->xp->evaluate($q, $ctx, $registerNodeNS);
}
/**
* Perform an xpath query and return only the 1st match
*
* @param String $q query string containing xpath
* @param \DOMNode $ctx (optional) Context DOMNode
* @param boolean $registerNodeNS Register flag pass thru
*
* @return fDOMNode
*/
public function queryOne($q, \DOMNode $ctx = NULL, $registerNodeNS = TRUE) {
if (is_null($this->xp)) {
$this->getDOMXPath();
}
return $this->xp->queryOne($q, $ctx, $registerNodeNS);
}
/**
* Forwarder to fDOMXPath's prepare method allowing for easy and secure
* placeholder replacement comparable to sql's prepared statements
* .
* @param string $xpath String containing xpath with :placeholder markup
* @param array $valueMap Array containing keys (:placeholder) and value pairs to be quoted
*
* @return string
*/
public function prepareQuery($xpath, array $valueMap) {
if (is_null($this->xp)) {
$this->getDOMXPath();
}
return $this->xp->prepare($xpath, $valueMap);
}
/**
* Use a CSS Level 3 Selector string to query select nodes
*
* @param string $selector A CSS Level 3 Selector string
* @param \DOMNode $ctx
* @param bool $registerNodeNS
*
* @return \DOMNodeList
*/
public function select($selector, \DOMNode $ctx = NULL, $registerNodeNS = TRUE) {
$translator = new Translator();
$xpath = $translator->translate($selector);
if ($ctx != NULL) {
$xpath = '.' . $xpath;
}
return $this->query($xpath, $ctx, $registerNodeNS);
}
/**
* Forward to DOMXPath->registerNamespace()
*
* @param string $prefix The prefix to use
* @param string $uri The uri to assign to this prefix
*
* @throws fDOMException
*
* @return void
*/
public function registerNamespace($prefix, $uri) {
if (is_null($this->xp)) {
$this->getDOMXPath();
}
if (!$this->xp->registerNamespace($prefix, $uri)) {
throw new fDOMException("Registering namespace '$uri' with prefix '$prefix' failed.", fDOMException::RegistrationFailed);
}
$this->prefixes[$prefix] = $uri;
}
/**
* Forward to DOMXPath->registerPHPFunctions()
*
* @param mixed $restrict Array of function names or string with functionname to restrict callabilty to
*
* @throws fDOMException
*
* @return void
*/
public function registerPHPFunctions($restrict = NULL) {
if (is_null($this->xp)) {
$this->getDOMXPath();
}
$this->xp->registerPHPFunctions($restrict);
if (libxml_get_last_error()) {
throw new fDOMException("Registering php functions failed.", fDOMException::RegistrationFailed);
}
}
/**
* Create a new element in namespace defined by given prefix
*
* @param string $prefix Namespace prefix for node to create
* @param string $name Name of not element to create
* @param string $content Optional content to be set
* @param bool $asTextNode Create content as textNode rather then setting nodeValue
*
* @throws fDOMException
*
* @return fDOMElement Reference to created fDOMElement
*/
public function createElementPrefix($prefix, $name, $content = NULL, $asTextNode = FALSE) {
if (!isset($this->prefixes[$prefix])) {
throw new fDOMException("'$prefix' not bound", fDOMException::UnboundPrefix);
}
return $this->createElementNS($this->prefixes[$prefix], $prefix.':'.$name, $content, $asTextNode);
}
/**
* Create a new fDOMElement and return it, optionally set content
*
* @param string $name Name of node to create
* @param null $content Content to set (optional)
* @param bool $asTextnode Create content as textNode rather then setting nodeValue
*
* @throws fDOMException
*
* @return fDOMElement Reference to created fDOMElement
*/
public function createElement($name, $content = NULL, $asTextnode = FALSE) {
try {
$node = parent::createElement($name);
if (!$node) {
throw new fDOMException("Creating element with name '$name' failed", fDOMException::NameInvalid);
}
if ($content !== NULL) {
if ($asTextnode) {
$node->appendChild($this->createTextnode($content));
} else {
$node->nodeValue = $content;
}
if (libxml_get_errors()) {
throw new fDOMException("Setting content value failed", fDOMException::SetFailedError);
}
}
return $this->ensureIntance($node);
} catch (\DOMException $e) {
throw new fDOMException("Creating elemnt with name '$name' failed", 0, $e);
}
}
/**
* Create a new fDOMElement within given namespace and return it
*
* @param string $namespace Namespace URI for node to create
* @param string $name Name of node to create
* @param string $content Content to set (optional)
* @param bool $asTextNode Create content as textNode rather then setting nodeValue
*
* @throws fDOMException
*
* @return fDOMElement
*/
public function createElementNS($namespace, $name, $content = NULL, $asTextNode = FALSE) {
$node = parent::createElementNS($namespace, $name);
if (!$node) {
throw new fDOMException("Creating element with name '$name' failed", fDOMException::NameInvalid);
}
if ($content !== NULL) {
if ($asTextNode) {
$node->appendChild($this->createTextnode($content));
} else {
$node->nodeValue = $content;
}
if (libxml_get_errors()) {
throw new fDOMException("Setting content value failed", fDOMException::SetFailedError);
}
}
return $this->ensureIntance($node);
}
/**
* @return fDOMDocumentFragment
*/
public function createDocumentFragment() {
return $this->ensureIntance(parent::createDocumentFragment());
}
/**
* Check if the given node is in the same document
*
* @param \DOMNode $node Node to compare with
*
* @return boolean true on match, false if they differ
*
*/
public function inSameDocument(\DOMNode $node) {
if ($node instanceof \DOMDocument) {
return $this->isSameNode($node);
}
return $this->isSameNode($node->ownerDocument);
}
/**
* Create a new element and append it as documentElement
*
* @param string $name Name of not element to create
* @param string $content Optional content to be set
* @param bool $asTextNode
*
* @return fDOMElement Reference to created fDOMElement
*/
public function appendElement($name, $content = NULL, $asTextNode = FALSE) {
return $this->appendChild(
$this->createElement($name, $content, $asTextNode)
);
}
/**
* Create a new element in given namespace and append it as documentElement
*
* @param string $ns Namespace of node to create
* @param string $name Name of not element to create
* @param string $content Optional content to be set
* @param bool $asTextNode
*
* @return fDOMElement Reference to created fDOMElement
*/
public function appendElementNS($ns, $name, $content = NULL, $asTextNode = FALSE) {
return $this->appendChild(
$this->createElementNS($ns, $name, $content, $asTextNode)
);
}
/**
* This is a workaround for hhvm's broken registerNodeClass handling
* (https://github.com/facebook/hhvm/issues/1848)
*
* @param \DOMNode $node
*
* @return \DOMNode
*/
private function ensureIntance(\DOMNode $node) {
if ($node instanceof fDOMNode || $node instanceof fDOMElement || $node instanceof fDOMDocumentFragment) {
return $node;
}
return $this->importNode($node, TRUE);
}
/**
* Register replacements
*
* Called from constructor and, as a workaround for (https://github.com/facebook/hhvm/issues/5412),
* after load(), loadXML(), loadHTML() and loadHTMLFile()
*/
private function registerNodeClasses() {
$this->registerNodeClass('DOMDocument', get_called_class());
$this->registerNodeClass('DOMNode', 'TheSeer\fDOM\fDOMNode');
$this->registerNodeClass('DOMElement', 'TheSeer\fDOM\fDOMElement');
$this->registerNodeClass('DOMDocumentFragment', 'TheSeer\fDOM\fDOMDocumentFragment');
}
} // fDOMDocument
}
fDOMDocument-1.6.1/TheSeer/fDOMDocument/fDOMElement.php 0000664 0001750 0001750 00000033525 12531446143 022333 0 ustar theseer theseer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Arne Blankerts nor the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER ORCONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @copyright Arne Blankerts , All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://github.com/theseer/fdomdocument
*
*/
namespace TheSeer\fDOM {
/**
* fDomElement
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @access public
* @property fDOMDocument $ownerDocument
*
*/
class fDOMElement extends \DOMElement {
/**
* @return string
*/
public function __toString() {
return $this->C14N();
}
/**
* Forward to fDomDocument->query()
*
* @param string $q XPath to use
* @param \DOMNode $ctx \DOMNode to overwrite context
* @param boolean $registerNodeNS Register flag pass thru
*
* @return \DomNodeList
*/
public function query($q, \DOMNode $ctx = null, $registerNodeNS = true) {
return $this->ownerDocument->query($q, $ctx ? $ctx : $this, $registerNodeNS);
}
/**
* Forward to fDomDocument->queryOne()
*
* @param string $q XPath to use
* @param \DOMNode $ctx (optional) \DOMNode to overwrite context
* @param boolean $registerNodeNS Register flag pass thru
*
* @return mixed
*/
public function queryOne($q, \DOMNode $ctx = null, $registerNodeNS = true) {
return $this->ownerDocument->queryOne($q, $ctx ? $ctx : $this, $registerNodeNS);
}
/**
* Forward to fDomDocument->select()
*
* @param string $selector A CSS Level 3 Selector string
* @param \DOMNode $ctx
* @param bool $registerNodeNS
*
* @return \DOMNodeList
*/
public function select($selector, \DOMNode $ctx = null, $registerNodeNS = true) {
return $this->ownerDocument->select($selector, $ctx, $registerNodeNS);
}
/**
* Parse and append XML String to node
*
* @param String $str string to process
*
* @return fDomDocumentFragment Reference to the created Fragment
*/
public function appendXML($str) {
$frag = $this->ownerDocument->createDocumentFragment();
$frag->appendXML($str);
$this->appendChild($frag);
return $frag;
}
/**
* Create a new element and append it
*
* @param string $name Name of not element to create
* @param string $content Optional content to be set
*
* @return fDOMElement Reference to created fDOMElement
*/
public function appendElement($name, $content = null) {
$node = $this->ownerDocument->createElement($name, $content);
$this->appendChild($node);
return $node;
}
/**
* Create a new element in given namespace and append it
*
* @param string $ns Namespace of node to create
* @param string $name Name of not element to create
* @param string $content Optional content to be set
*
* @return fDOMElement Reference to created fDOMElement
*/
public function appendElementNS($ns, $name, $content = null) {
$node = $this->ownerDocument->createElementNS($ns, $name, $content);
$this->appendChild($node);
return $node;
}
/**
* Create a new element in given namespace and append it
*
* @param string $prefix Namespace prefix for node to create
* @param string $name Name of not element to create
* @param string $content Optional content to be set
*
* @return fDOMElement Reference to created fDOMElement
*/
public function appendElementPrefix($prefix, $name, $content = null) {
$node = $this->ownerDocument->createElementPrefix($prefix, $name, $content);
$this->appendChild($node);
return $node;
}
/**
* Create a new text node and append it
*
* @param string $content Text content to be added
*
* @return \DOMText
*/
public function appendTextNode($content) {
$text = $this->ownerDocument->createTextNode($content);
$this->appendChild($text);
return $text;
}
/**
* Create a new fDOMElement
*
* @see fDOMDocument::createElement
*
* @param string $name
* @param string $content
* @param bool $asTextnode
*
* @return fDOMElement
*/
public function createElement($name, $content = NULL, $asTextnode = FALSE) {
return $this->ownerDocument->createElement($name, $content, $asTextnode);
}
/**
* Create a new fDOMElement in namespace defined by prefix
*
* @see fDOMDocument::createElementPrefix
*
* @param string $prefix
* @param string $name
* @param string $content
* @param bool $asTextNode
*
* @return fDOMElement
*/
public function createElementPrefix($prefix, $name, $content = NULL, $asTextNode = FALSE) {
return $this->ownerDocument->createElementPrefix($prefix, $name, $content, $asTextNode);
}
/**
* Create a new fDOMElement within given namespace and return it
*
* @param string $namespace Namespace URI for node to create
* @param string $name Name of node to create
* @param null $content Content to set (optional)
* @param bool $asTextNode Create content as textNode rather then setting nodeValue
*
* @throws fDOMException
*
* @return fDOMElement
*/
public function createElementNS($namespace, $name, $content = NULL, $asTextNode = FALSE) {
return $this->ownerDocument->createElementNS($namespace, $name, $content, $asTextNode);
}
/**
* Wrapper to DomElement->getAttribute with default value option
*
* Note: A set but emptry attribute does NOT trigger use of the default
*
* @param string $attr Attribute to access
* @param string $default Default value to use if the attribute is not set
*
* @return string
*/
public function getAttribute($attr, $default='') {
return $this->hasAttribute($attr) ? parent::getAttribute($attr) : $default;
}
/**
* Wrapper to DomElement->getAttributeNS with default value option
*
* Note: A set but empty attribute does NOT trigger use of the default
*
* @param string $ns Namespace of attribute
* @param string $attr Attribute to access
* @param string $default Default value to use if the attribute is not set
*
* @return string
*/
public function getAttributeNS($ns, $attr, $default='') {
return $this->hasAttributeNS($ns, $attr) ? parent::getAttributeNS($ns, $attr) : $default;
}
/**
* Wrapper to DOMElement::setAttribute with additional entities support
*
* @param string $attr Attribute name to set
* @param string $value Value to set attribute to
* @param bool $keepEntities Flag to signale if entities should be kept
*
* @throws fDOMException
*
* @return \DOMAttr
*
* @see DOMElement::setAttribute()
*/
public function setAttribute($attr, $value, $keepEntities=false) {
if ($keepEntities === true) {
$attrNode = $this->ownerDocument->createAttribute($attr);
if (!$attrNode) {
throw new fDOMException("Setting attribute '$attr' failed.", fDOMException::SetFailedError);
}
$attrNode->value = $value;
$this->appendChild($attrNode);
return $attrNode;
}
return parent::setAttribute($attr, $value);
}
/**
* Wrapper to namespace aware DOMElement::setAttributeNS with additional entities support
*
* @param string $ns namespace attribute should be in
* @param string $attr Attribute name to set
* @param string $value Value to set attribute to
* @param bool $keepEntities Flag to signale if entities should be kept
*
* @throws fDOMException
*
* @return \DOMAttr|null
* @see DOMElement::setAttribute()
*/
public function setAttributeNS($ns, $attr, $value, $keepEntities=false) {
if ($keepEntities === true) {
$attrNode = $this->ownerDocument->createAttributeNS($ns, $attr);
if (!$attrNode) {
throw new fDOMException("Setting attribute '$attr' failed.", fDOMException::SetFailedError);
}
$attrNode->value = $value;
$this->appendChild($attrNode);
return $attrNode;
}
return parent::setAttributeNS($ns, $attr, $value);
}
/**
* Helper to add multiple attributes to an element
*
* @param array $attr Attributes to add as key-value pair
* @param bool $keepEntities Flag wether to keep entities
*
* @return array List with references to created DOMAttr
*/
public function setAttributes(array $attr, $keepEntities=false) {
$attList = array();
foreach($attr as $name => $value) {
$attList[] = $this->setAttribute($name, $value, $keepEntities);
}
return $attList;
}
/**
* Helper to add multiple attributes with the given namespace and prefix
*
* @param string $ns Namespace of attribute
* @param string $prefix Namespace prefix for attribute to create
* @param array $attr Attributes to add
* @param bool $keepEntities Flag wether to keep entities
*
* @return void
*/
public function setAttributesNS($ns, $prefix, array $attr, $keepEntities=false) {
foreach($attr as $name => $value) {
$this->setAttributeNS($ns, $prefix.':'.$name, $value, $keepEntities);
}
}
/**
* Helper method to get children by name
*
* @param string $tagName tagname to search for
*
* @return \DOMNodeList
*/
public function getChildrenByTagName($tagName) {
return $this->query("*[local-name()='$tagName']");
}
/**
* Helper method to get children by name and namespace
*
* @param string $ns namespace nodes have to be in
* @param string $tagName tagname to search for
*
* @return \DOMNodeList
*/
public function getChildrenByTagNameNS($ns, $tagName) {
return $this->query("*[local-name()='$tagName' and namespace-uri()='$ns']");
}
/**
* Check if the given node is in the same document
*
* @param \DomNode $node Node to compare with
*
* @return boolean true on match, false if they differ
*
*/
public function inSameDocument(\DomNode $node) {
return $this->ownerDocument->inSameDocument($node);
}
/**
* Wrapper to DomDocument::saveXML() with current node as context
*
* @return string
*/
public function saveXML() {
return $this->ownerDocument->saveXML($this);
}
/**
* Wrapper to DomDocument::saveHTML() with current node as context
*
* @return string
*/
public function saveHTML() {
return $this->ownerDocument->saveHTML($this);
}
} // fDOMElement
}
fDOMDocument-1.6.1/TheSeer/fDOMDocument/fDOMException.php 0000664 0001750 0001750 00000013251 12531446143 022672 0 ustar theseer theseer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Arne Blankerts nor the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER ORCONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @package fDOM
* @author Arne Blankerts
* @copyright Arne Blankerts , All rights reserved.
* @license BSD License
*/
namespace TheSeer\fDOM {
/**
* fDOMException
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @access public
*
*/
class fDOMException extends \Exception {
const LoadError = 1;
const ParseError = 2;
const SaveError = 3;
const QueryError = 4;
const RegistrationFailed = 5;
const NoDOMXPath = 6;
const UnboundPrefix = 7;
const SetFailedError = 8;
const NameInvalid = 9;
/**
* List of libxml error objects
*
* @var array
*/
private $errorList;
/**
* Full Error message
*
* @var string
*/
private $fullMessage = null;
/**
* Short Error Message
*
* @var string
*/
private $shortMessage = null;
private static $fullMesageMode = true;
/**
* Constructor
*
* @param string $message Exception message
* @param integer $code Exception code
* @param \Exception $chain optional chained exception
*
*/
public function __construct($message, $code = 0, \Exception $chain = NULL) {
$this->shortMessage = $message;
$this->errorList = libxml_get_errors();
libxml_clear_errors();
parent :: __construct($message, $code, $chain);
$this->fullMessage = $message."\n\n";
foreach ($this->errorList as $error) {
// hack, skip "attempt to load external pseudo error"
if ($error->code=='1543') {
continue;
}
if (empty($error->file)) {
$this->fullMessage .= '[XML-STRING] ';
} else {
$this->fullMessage .= '['.$error->file.'] ';
}
$this->fullMessage .= '[Line: '.$error->line.' - Column: '.$error->column.'] ';
switch ($error->level) {
case LIBXML_ERR_WARNING:
$this->fullMessage .= "Warning $error->code: ";
break;
case LIBXML_ERR_ERROR:
$this->fullMessage .= "Error $error->code: ";
break;
case LIBXML_ERR_FATAL:
$this->fullMessage .= "Fatal Error $error->code: ";
break;
}
$this->fullMessage .= str_replace("\n", '', $error->message)."\n";
if (self::$fullMesageMode) {
$this->message = $this->fullMessage;
}
}
}
/**
* Accessor to fullMessage
*
* @return string
*/
public function getFullMessage() {
return $this->fullMessage;
}
/**
* Access to shortMessage
*
* @return string
*/
public function getShortMessage() {
return $this->shortMessage;
}
/**
* Accessor to errorList objets
*
* @return array
*/
public function getErrorList() {
return $this->errorList;
}
/**
* Toggle wehter getMessage() should return full or only exception message
*
* @param boolean $full Flag to enable or disable full message output
*
* @return void
*/
public function toggleFullMessage($full = true) {
$this->message = $full ? $this->fullMessage : $this->shortMessage;
}
/**
* Magic method for string context
*
* @return string
*/
public function __toString() {
return $this->fullMessage;
}
} // fDOMException
}
fDOMDocument-1.6.1/TheSeer/fDOMDocument/fDOMNode.php 0000664 0001750 0001750 00000014332 12531446143 021622 0 ustar theseer theseer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Arne Blankerts nor the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER ORCONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @copyright Arne Blankerts , All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://github.com/theseer/fdomdocument
*
*/
namespace TheSeer\fDOM {
/**
* fDomNode
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @access public
* @property fDOMDocument $ownerDocument
*
*/
class fDOMNode extends \DOMNode {
/**
* @return string
*/
public function __toString() {
return $this->C14N();
}
/**
* Create a new fDOMElement
*
* @see fDOMDocument::createElement
*
* @param string $name
* @param string $content
* @param bool $asTextnode
*
* @return fDOMElement
*/
public function createElement($name, $content = NULL, $asTextnode = FALSE) {
return $this->ownerDocument->createElement($name, $content, $asTextnode);
}
/**
* Create a new fDOMElement in namespace defined by prefix
*
* @see fDOMDocument::createElementPrefix
*
* @param string $prefix
* @param string $name
* @param string $content
* @param bool $asTextNode
*
* @return fDOMElement
*/
public function createElementPrefix($prefix, $name, $content = NULL, $asTextNode = FALSE) {
return $this->ownerDocument->createElementPrefix($prefix, $name, $content, $asTextNode);
}
/**
* Create a new fDOMElement within given namespace and return it
*
* @param string $namespace Namespace URI for node to create
* @param string $name Name of node to create
* @param null $content Content to set (optional)
* @param bool $asTextNode Create content as textNode rather then setting nodeValue
*
* @throws fDOMException
*
* @return fDOMElement
*/
public function createElementNS($namespace, $name, $content = NULL, $asTextNode = FALSE) {
return $this->ownerDocument->createElementNS($namespace, $name, $content, $asTextNode);
}
/**
* Forward to fDomDocument->query()
*
* @param string $q XPath to use
* @param \DOMNode $ctx \DOMNode to overwrite context
* @param boolean $registerNodeNS Register flag pass thru
*
* @return \DomNodeList
*/
public function query($q, \DOMNode $ctx = null, $registerNodeNS = true) {
return $this->ownerDocument->query($q, $ctx ? $ctx : $this, $registerNodeNS);
}
/**
* Forward to fDomDocument->queryOne()
*
* @param string $q XPath to use
* @param \DOMNode $ctx (optional) \DOMNode to overwrite context
* @param boolean $registerNodeNS Register flag pass thru
*
* @return mixed
*/
public function queryOne($q, \DOMNode $ctx = null, $registerNodeNS = true) {
return $this->ownerDocument->queryOne($q, $ctx ? $ctx : $this, $registerNodeNS);
}
/**
* Forward to fDomDocument->select()
*
* @param string $selector A CSS Level 3 Selector string
* @param \DOMNode $ctx
* @param bool $registerNodeNS
*
* @return \DOMNodeList
*/
public function select($selector, \DOMNode $ctx = null, $registerNodeNS = true) {
return $this->ownerDocument->select($selector, $ctx, $registerNodeNS);
}
/**
* Check if the given node is in the same document
*
* @param \DomNode $node Node to compare with
*
* @return boolean true on match, false if they differ
*
*/
public function inSameDocument(\DOMNode $node) {
return $this->ownerDocument->inSameDocument($node);
}
/**
* Wrapper to DomDocument::saveXML() with current node as context
*
* @return string
*/
public function saveXML() {
return $this->ownerDocument->saveXML($this);
}
/**
* Wrapper to DomDocument::saveHTML() with current node as context
*
* @return string
*/
public function saveHTML() {
return $this->ownerDocument->saveHTML($this);
}
} // fDOMNode
}
fDOMDocument-1.6.1/TheSeer/fDOMDocument/fDOMXPath.php 0000664 0001750 0001750 00000012741 12531446143 021763 0 ustar theseer theseer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Arne Blankerts nor the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER ORCONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @copyright Arne Blankerts , All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://github.com/theseer/fdomdocument
*
*/
namespace TheSeer\fDOM {
/**
* fDOMXPath extension to PHP's DOMXPath.
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @access public
*
*/
class fDOMXPath extends \DOMXPath {
/**
* @var \DOMDocument
*/
protected $doc;
/**
* @param \DOMDocument $doc
*/
public function __construct(\DOMDocument $doc) {
parent::__construct($doc);
$this->doc = $doc;
}
/**
* @param string $xpath
* @param array $valueMap
*
* @return string
*/
public function prepare($xpath, array $valueMap) {
if (count($valueMap)==0) {
return $xpath;
}
foreach($valueMap as $key => $value) {
$xpath = str_replace(':'.$key, $this->quote($value), $xpath);
}
return $xpath;
}
/**
* @param string $q
* @param \DOMNode $ctx
* @param bool $registerNodeNS
*
* @throws fDOMException
*
* @return \DOMNodeList
*/
public function query($q, \DOMNode $ctx = null, $registerNodeNS = true) {
libxml_clear_errors();
if (version_compare(PHP_VERSION, '5.3.3', '<') || strpos(PHP_VERSION, 'hiphop') || strpos(PHP_VERSION, 'hhvm')) {
$rc = parent::query($q, ($ctx instanceof \DOMNode) ? $ctx : $this->doc->documentElement);
} else {
$rc = parent::query($q, ($ctx instanceof \DOMNode) ? $ctx : $this->doc->documentElement, $registerNodeNS);
}
if (libxml_get_last_error()) {
throw new fDOMException('evaluating xpath expression failed.', fDOMException::QueryError);
}
return $rc;
}
/**
* @param string $q
* @param \DOMNode $ctx
* @param bool $registerNodeNS
*
* @throws fDOMException
*
* @return mixed
*/
public function evaluate($q, \DOMNode $ctx = null, $registerNodeNS = true) {
libxml_clear_errors();
if (version_compare(PHP_VERSION, '5.3.3', '<') || strpos(PHP_VERSION, 'hiphop') || strpos(PHP_VERSION, 'hhvm')) {
$rc = parent::evaluate($q, ($ctx instanceof \DOMNode) ? $ctx : $this->doc->documentElement);
} else {
$rc = parent::evaluate($q, ($ctx instanceof \DOMNode) ? $ctx : $this->doc->documentElement, $registerNodeNS);
}
if (libxml_get_last_error()) {
throw new fDOMException('evaluating xpath expression failed.', fDOMException::QueryError);
}
return $rc;
}
/**
* @param string $q
* @param \DOMNode $ctx
* @param bool $registerNodeNS
*
* @throws fDOMException
*
* @return \DOMNode|mixed
*/
public function queryOne($q, \DOMNode $ctx = null, $registerNodeNS = true) {
$rc = $this->evaluate($q, $ctx, $registerNodeNS);
if ($rc instanceof \DOMNodelist) {
return $rc->item(0);
}
return $rc;
}
/**
* @param string $str
*
* @return string
*/
public function quote($str) {
if (strpos($str, '"') === false) {
return '"'.$str.'"';
}
$parts = explode('"', $str);
return 'concat("' . join('",\'"\',"', $parts).'")';
}
}
}
fDOMDocument-1.6.1/TheSeer/fDOMDocument/XPathQuery.php 0000664 0001750 0001750 00000014227 12531446143 022304 0 ustar theseer theseer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Arne Blankerts nor the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER ORCONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @copyright Arne Blankerts , All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://github.com/theseer/fdomdocument
*
*/
namespace TheSeer\fDOM {
/**
* Class XPathQuery
*
* @package TheSeer\fDOM
*/
class XPathQuery {
/**
* @var string
*/
private $query;
/**
* Key-value Map for bound values
*
* @var array
*/
private $values = array();
/**
* @param string $query
*/
public function __construct($query) {
$this->setQuery($query);
}
/**
* Set Query.
*
* @param string $query
*/
private function setQuery($query) {
$this->query = $query;
$res = preg_match_all('/(:(\w*))/', $query, $matches);
if ($res > 0) {
$this->values = array_fill_keys($matches[2], '');
}
}
/**
* Returns keys.
*
* @return array
*/
public function getKeys() {
return array_keys($this->values);
}
/**
* Bind value to key.
*
* @param string $key
* @param string $value
*
* @throws XPathQueryException
*/
public function bind($key, $value) {
if (!array_key_exists($key, $this->values)) {
throw new XPathQueryException("'$key' not found in query'", XPathQueryException::KeyNotFound );
}
$this->values[$key] = $value;
}
/**
* Generate query.
*
* @param \DOMNode $ctx
* @param array $values
*
* @return string
*/
public function generate(\DOMNode $ctx, array $values = NULL) {
return $this->buildQuery($this->getXPathObjectFor($ctx), $values);
}
/**
* Evaluate Query.
*
* @param \DOMNode $ctx
* @param array $values
* @param bool $registerNodeNS
*
* @throws fDOMException
*
* @return mixed
*/
public function evaluate(\DOMNode $ctx, array $values = NULL, $registerNodeNS = TRUE) {
$xp = $this->getXPathObjectFor($ctx);
return $xp->evaluate($this->buildQuery($xp, $values), $ctx, $registerNodeNS);
}
/**
* Execute Query.
*
* @param \DOMNode $ctx
* @param array $values
* @param bool $registerNodeNS
*
* @throws fDOMException
*
* @return mixed
*/
public function query(\DOMNode $ctx, array $values = NULL, $registerNodeNS = TRUE) {
$xp = $this->getXPathObjectFor($ctx);
return $xp->evaluate($this->buildQuery($xp, $values), $ctx, $registerNodeNS);
}
/**
* Execute Query and return first result.
*
* @param \DOMNode $ctx
* @param array $values
* @param bool $registerNodeNS
*
* @return \DOMNode
*/
public function queryOne(\DOMNode $ctx, array $values = NULL, $registerNodeNS = TRUE) {
$xp = $this->getXPathObjectFor($ctx);
return $xp->queryOne($this->buildQuery($xp, $values), $ctx, $registerNodeNS);
}
/**
* Return xPath for node
*
* @param \DOMNode $ctx
*
* @throws fDOMException
*
* @return fDOMXPath
*/
private function getXPathObjectFor(\DOMNode $ctx) {
$dom = $ctx instanceof \DOMDocument ? $ctx : $ctx->ownerDocument;
if ($dom instanceOf fDOMDocument) {
return $dom->getDOMXPath();
}
return new fDOMXPath($dom);
}
/**
* Build query using values.
*
* @param fDOMXPath $xp
* @param array $values
*
* @throws XPathQueryException
*
* @return string
*/
private function buildQuery(fDOMXPath $xp, array $values = NULL) {
$backup = $this->values;
if (count($values) > 0) {
foreach($values as $k => $v) {
$this->bind($k, $v);
}
}
$query = $xp->prepare($this->query, $this->values);
$this->values = $backup;
return $query;
}
}
}
fDOMDocument-1.6.1/TheSeer/fDOMDocument/XPathQueryException.php 0000664 0001750 0001750 00000003770 12531446143 024164 0 ustar theseer theseer
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of Arne Blankerts nor the names of contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT * NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER ORCONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*
* @category PHP
* @package TheSeer\fDOM
* @author Arne Blankerts
* @copyright Arne Blankerts , All rights reserved.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://github.com/theseer/fdomdocument
*
*/
namespace TheSeer\fDOM {
class XPathQueryException extends \Exception {
const KeyNotFound = 1;
}
}
fDOMDocument-1.6.1/tests/_data/broken.xml 0000664 0001750 0001750 00000000133 12531446143 020101 0 ustar theseer theseer