pax_global_header00006660000000000000000000000064124357023240014514gustar00rootroot0000000000000052 comment=a9246376c713156e55c080782d4104bb07d4b899 fXSL-1.1.1/000077500000000000000000000000001243570232400123305ustar00rootroot00000000000000fXSL-1.1.1/.gitignore000066400000000000000000000000771243570232400143240ustar00rootroot00000000000000.buildpath .settings .project build vendor composer.lock .idea fXSL-1.1.1/.travis.yml000066400000000000000000000002071243570232400144400ustar00rootroot00000000000000language: php php: - 5.3 - 5.4 - 5.5 - hhvm notifications: email: false matrix: allow_failures: - php: hhvm fXSL-1.1.1/LICENSE000066400000000000000000000027521243570232400133430ustar00rootroot00000000000000fXSL Copyright (c) 2010-2014 Arne Blankerts 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. fXSL-1.1.1/build.xml000066400000000000000000000057061243570232400141610ustar00rootroot00000000000000 fXSL-1.1.1/composer.json000066400000000000000000000011631243570232400150530ustar00rootroot00000000000000{ "name" : "theseer/fxsl", "description" : "An XSL wrapper / extension to the PHP 5.x XSLTProcessor with Exception and extended Callback support", "license" : "BSD-2-Clause", "authors" : [ { "name" : "Arne Blankerts", "email" : "arne@blankerts.de", "role" : "Developer" } ], "require" : { "php" : ">=5.3.3", "ext-libxml" : "*", "ext-dom" : "*", "ext-xsl" : "*" }, "support" : { "issues" : "https://github.com/theseer/fXSL/issues" }, "autoload" : { "classmap" : [ "src/" ] }, "extra" : { "branch-alias": { "dev-master": "1.0.x-dev" } } } fXSL-1.1.1/package.xml000066400000000000000000000051231243570232400144460ustar00rootroot00000000000000 fXSL pear.netpirates.net An XSL wrapper / extension to the PHP 5.x XSLTProcessor An experimental XSL wrapper / extension to the PHP 5.x XSLTProcessor Arne Blankerts theseer arne@blankerts.de yes 2014-11-27 1.1.1 1.1.0 stable stable BSD License http://github.com/theseer/fDOMDocument/tree 5.3.3 1.9.1 libxml dom xsl fXSL-1.1.1/pear.sh000077500000000000000000000004171243570232400136200ustar00rootroot00000000000000#!/bin/sh rm -f fXSL*.tgz mkdir -p tmp/TheSeer/fXSL mkdir -p tmp/tests cp -r src/* tmp/TheSeer/fXSL cp -r tests/* tmp/tests cp package.xml phpunit.xml.dist LICENSE tmp phpab -o tmp/TheSeer/fXSL/autoload.php -b src src cd tmp pear package mv fXSL*.tgz .. cd .. rm -rf tmp fXSL-1.1.1/phpcs.xml000066400000000000000000000026171243570232400141750ustar00rootroot00000000000000 Arne Blankerts' coding standard fXSL-1.1.1/phpunit.xml.dist000066400000000000000000000014761243570232400155130ustar00rootroot00000000000000 tests src fXSL-1.1.1/readme.markdown000066400000000000000000000072251243570232400153370ustar00rootroot00000000000000fXSL ============ The classes contained within this repository extend the standard XSLTProcessor to use exceptions at all occasions of errors instead of PHP warnings, notices or semi completed transformations. They also add various custom methods and shortcuts for convinience and to allow a nicer API to implement callbacks to the PHP stack. Requirements ------------ PHP: 5.3.3 (5.3.0-5.3.2 had serious issues with spl stacked autoloaders) Extensions: dom, xsl, libxml Installation ------------ fXSL can be installed using the PEAR Installer, the backbone of the PHP Extension and Application Repository that provides a distribution system for PHP packages. Depending on your OS distribution and/or your PHP environment, you may need to install PEAR or update your existing PEAR installation before you can proceed with the instructions in this chapter. ``sudo pear upgrade PEAR`` usually suffices to upgrade an existing PEAR installation. The PEAR Manual explains how to perform a fresh installation of PEAR. The following two commands are all that is required to install fDOMDocument using the PEAR Installer: sudo pear channel-discover pear.netpirates.net sudo pear install TheSeer/fXSL After the installation you can find the source files inside your local PEAR directory; the path is usually either ``/usr/share/pear/TheSeer/fXSL`` (Fedora/Redhat) or ``/usr/lib/php/TheSeer/fXSL`` (Debian/Ubuntu). Usage ----- Simply require/include the autoload.php supplied and you can start using fXSL as a drop in replacement for the standard XSLTProcessor. Usage Samples ------------- PHP Code: loadXML(''); $p = $x->createTextNode($a . ' -> ' . $b); $x->documentElement->appendChild($p); return $x->documentElement; } } $tpl = new DOMDocument(); $tpl->load('test.xsl'); $dom = new DOMDocument(); $xsl = new fXSLTProcessor($tpl); $xsl->registerPHPFunctions('demo'); $test = new fXSLCallback('test:only','test'); $test->setObject(new foo()); $xsl->registerCallback($test); $result = $xsl->transformToXml($dom); $tpl->formatOutput = true; echo "Template:\n" . $tpl->saveXML(); echo "\n\nOutput:\n".$result; ?> The 'test.xsl' XSL Stylesheet used: Changelog --------- #####Release 1.1.0 * Added loadStylesheetFromFile and loadStylesheetFromXML methods * Clear xml errors on construct * Changed protected properties and methods to private #####Release 1.0.4 * PHP 5.4 compatibilty: set a default security preference so writing files is allowed #####Release 1.0.3 * Changed error detecting code to catch more problems #####Release 1.0.2 * Extended Exception code to better show actual errors #####Release 1.0.1 * Added support for black- and whitelisting of methods * Generate nicer xsl code * Various Bugfixes #####Release 1.0.0 * Initial release fXSL-1.1.1/sample/000077500000000000000000000000001243570232400136115ustar00rootroot00000000000000fXSL-1.1.1/sample/demo.php000066400000000000000000000015201243570232400152440ustar00rootroot00000000000000loadXML(''); $p = $x->createTextNode($a . ' -> ' . $b); $x->documentElement->appendChild($p); return $x->documentElement; } } $tpl = new DOMDocument(); $tpl->load('test.xsl'); $dom = new DOMDocument(); $xsl = new fXSLTProcessor($tpl); $xsl->registerPHPFunctions('demo'); $test = new fXSLCallback('test:only','test'); $test->setObject(new foo()); $xsl->registerCallback($test); $result = $xsl->transformToXml($dom); $tpl->formatOutput = true; echo "Template:\n" . $tpl->saveXML(); echo "\n\nOutput:\n".$result; fXSL-1.1.1/sample/test.xsl000066400000000000000000000010051243570232400153140ustar00rootroot00000000000000 fXSL-1.1.1/src/000077500000000000000000000000001243570232400131175ustar00rootroot00000000000000fXSL-1.1.1/src/autoload.php000066400000000000000000000012261243570232400154410ustar00rootroot00000000000000 '/fxslcallback.php', 'theseer\\fxsl\\fxsltprocessor' => '/fxsltprocessor.php', 'theseer\\fxsl\\fxsltprocessorexception' => '/fxsltprocessor.php' ); } $cn = strtolower($class); if (isset($classes[$cn])) { require __DIR__ . $classes[$cn]; } } ); // @codeCoverageIgnoreEndfXSL-1.1.1/src/fxslcallback.php000066400000000000000000000215161243570232400162660ustar00rootroot00000000000000 * 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\fXSL * @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/fxsl * */ namespace TheSeer\fXSL { /** * fXSLCallback * * This is a wrapper class around objects that are to be used for callbacks by fXSLTProcessor. * * It generates namespaced functions mapping the actual call to easy to use xpath functions, injecting * the required func and result nodes into the stylesheet * * @category PHP * @package TheSeer\fXSL * @author Arne Blankerts * @access public */ class fXSLCallback { /** * The namespace to be used for the callback functions * * @var string */ private $xmlns; /** * The prefix used for mapping the xsl function calls * * @var string */ private $prefix; /** * The registerd instance of the wrapped class * * @var object */ private $object; /** * List of blacklisted method names * * @var array */ private $blacklist = NULL; /** * List of whitelisted method names * * @var array */ private $whitelist = NULL; /** * Constructor * * @param string $xmlns The namespace to use * @param string $prefix The prefix to map the namespace to */ public function __construct($xmlns = '', $prefix = '') { $this->xmlns = $xmlns; $this->prefix = $prefix; } /** * Setter Method to define the Object to be wrapped * * @param $object * * @return void */ public function setObject($object) { $this->object = $object; } /** * Getter to get the currently registered Object * * @return Object */ public function getObject() { return $this->object; } /** * Setter method to define a whitelist of methods that can be called from xsl * * @param array $methods */ public function setWhitelist(array $methods) { $this->whitelist = $methods; } /** * Setter method to define a blacklist of methods that can not be called from xsl * * @param array $methods */ public function setBlacklist(array $methods) { $this->blacklist = $methods; } /** * Getter to get the namespace set at construction time * * @return string */ public function getNamespace() { return $this->xmlns; } /** * Helper to inject the needed exslt function nodes in an XSL Stylesheet * * @param \DomDocument $stylesheet Stylesheet to inject the wrapper code into * @param String $key Instance hash used for mapping in fXSLTProcessor * * @return void */ public function injectCallbackCode(\DomDocument $stylesheet, $key) { $root = $stylesheet->documentElement; $this->setStylesheetProperties($root); $frag = $stylesheet->createDocumentFragment(); $frag->appendXML("\n\n"); $rfo = new \ReflectionObject($this->object); $methods = $rfo->getMethods(\ReflectionMethod::IS_PUBLIC & ~\ReflectionMethod::IS_STATIC); if (!empty($methods)) { $this->registerMethods($frag, $key, $methods); } $frag->appendXML("\n\n"); $root->appendChild($frag); } /** * Internal helper to set the needed attributes on the xsl:stylesheet node * * @param \DOMElement $node */ private function setStylesheetProperties(\DOMElement $node) { $node->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:func', 'http://exslt.org/functions'); $node->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:php', 'http://php.net/xsl'); $node->setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:' . $this->prefix, $this->xmlns); $eep = explode(' ', $node->getAttribute('extension-element-prefixes')); $eep = array_unique(array_merge($eep, array('php', 'func'))); $node->setAttribute('extension-element-prefixes', trim(join(' ', $eep))); $erp = explode(' ', $node->getAttribute('exclude-result-prefixes')); $erp = array_unique(array_merge($erp, array('php', 'func', $this->prefix))); $node->setAttribute('exclude-result-prefixes', trim(join(' ', $erp))); } /** * Internal helper to register a list of methods as xsl functions * * @param \DomDocumentFragment $ctx A DomDocumentFragement to inject the method code into * @param string $key The hash of the class instance to refer to * @param Array $methods An array of ReflectionMethod object instances to register */ private function registerMethods(\DomDocumentFragment $ctx, $key, Array $methods) { $xslPrefix = $ctx->ownerDocument->lookupPrefix('http://www.w3.org/1999/XSL/Transform'); foreach ($methods as $m) { /** @var \ReflectionMethod $m */ if ((!empty($this->blacklist) && in_array($m->getName(), $this->blacklist)) || (!empty($this->whitelist) && !in_array($m->getName(), $this->whitelist)) ) { continue; } $xml = sprintf( '', $this->prefix, $this->xmlns, $this->prefix, $m->getName() ); $payload = array(); foreach ($m->getParameters() as $p) { // TODO: Check the type and bail out if it's not possible to provide it from xsl context $xml .= sprintf('<%s:param xmlns:%s="http://www.w3.org/1999/XSL/Transform" name="%s" />', $xslPrefix, $xslPrefix, $p->getName()); // TODO: Add string() wrapper if needed $payload[] = '$' . $p->getName(); } $xml .= sprintf( '', '\TheSeer\fXSL\fXSLTProcessor::callbackHook', $key, $this->xmlns, $m->getName(), count($payload) ? ', ' . join(', ', $payload) : '' ); $xml .= ''; $ctx->appendXML($xml); } } } }fXSL-1.1.1/src/fxsltprocessor.php000066400000000000000000000277661243570232400167520ustar00rootroot00000000000000 * 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\fXSL * @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/fxsl * */ namespace TheSeer\fXSL { /** * fXSLTProcessor * * This class extends the original XSLTProcessor with custom funcationality * to allow nicer php level callbacks and use exceptions in favor of * semi-complete documents and standard php errors * * Note: This code switches to libxml internal errors mode * * @category PHP * @package TheSeer\fXSL * @author Arne Blankerts * @access public */ class fXSLTProcessor extends \XSLTProcessor { /** * Static registry for registered callback objects * * @var array */ private static $registry = array(); /** * Flag to signal if initStyleSheet has been called * * @var boolean */ private $initDone = FALSE; /** * Flag to signal if registerPHPFunctions has been called * * @var boolean */ private $registered = FALSE; /** * The given XSL Stylesheet to process * * @var \DOMDocument */ private $stylesheet; /** * The spl_object_hash of the current instance * * @var string */ private $hash; /** * Constructor, allowing to directly inject a Stylesheet for later processing * * @param \DomDocument $stylesheet A DomDocument containing an xslt stylesheet */ public function __construct(\DomDocument $stylesheet = NULL) { $this->hash = spl_object_hash($this); libxml_use_internal_errors(TRUE); libxml_clear_errors(); if ($stylesheet !== NULL) { $this->importStylesheet($stylesheet); } if (method_exists($this, 'setSecurityPrefs')) { $this->setSecurityPrefs(XSL_SECPREF_NONE); } } /** * Destructor to cleanup registry */ public function __destruct() { unset(self::$registry[$this->hash]); } /** * Load a Stylesheet from a file and import it * * @param string $filename Filename to load as stylesheet */ public function loadStylesheetFromFile($filename) { $dom = new \DOMDocument(); $dom->load($filename); if (count(libxml_get_errors()) != 0) { throw new fXSLTProcessorException('Error loading stylesheet', fXSLTProcessorException::ImportFailed); } $this->importStylesheet($dom); } /** * Load a Stylesheet from xml string and import it * * @param string $xml XML string of stylesheet */ public function loadStylesheetFromXML($xml) { $dom = new \DOMDocument(); $dom->loadXML($xml); if (count(libxml_get_errors()) != 0) { throw new fXSLTProcessorException('Error loading stylesheet', fXSLTProcessorException::ImportFailed); } $this->importStylesheet($dom); } /** * @see XSLTProcessor::importStylesheet() * * Extended version to throw exception on error */ public function importStylesheet($stylesheet) { if ($stylesheet->documentElement->namespaceURI != 'http://www.w3.org/1999/XSL/Transform') { throw new fXSLTProcessorException( "Namespace mismatch: Expected 'http://www.w3.org/1999/XSL/Transform' but '{$stylesheet->documentElement->namespaceURI}' found.", fXSLTProcessorException::WrongNamespace ); } $this->stylesheet = $stylesheet; } /** * @see XSLTProcessor::registerPHPFunctions() * * Extended version to enforce callability of fXSLProcessor::callbackHook and generally callable methods */ public function registerPHPFunctions($restrict = NULL) { if (is_string($restrict)) { $restrict = array($restrict); } if (is_array($restrict)) { foreach ($restrict as $func) { if (!is_callable($func)) { throw new fXSLTProcessorException("'$func' is not a callable method or function", fXSLTProcessorException::NotCallable); } } $restrict[] = '\TheSeer\fXSL\fXSLTProcessor::callbackHook'; } $restrict === NULL ? parent::registerPHPFunctions() : parent::registerPHPFunctions($restrict); $this->registered = TRUE; } /** * @see XSLTProcessor::transformToDoc() * Extended version to throw exception on error */ public function transformToDoc($node) { if (!$this->initDone) { $this->initStylesheet(); } libxml_clear_errors(); $rc = parent::transformToDoc($node); if (count(libxml_get_errors()) != 0) { throw new fXSLTProcessorException('Error in transformation', fXSLTProcessorException::TransformationFailed); } return $rc; } /** * @see XSLTProcessor::transformToUri() * Extended version to throw exception on error * */ public function transformToUri($doc, $uri) { return $this->transformToDoc($doc)->save($uri); } /** * @see XSLTProcessor::transformToXml() * Extended version to throw exception on error * */ public function transformToXml($doc) { if (!$this->initDone) { $this->initStylesheet(); } // Do not remap this to $this->transformToDoc(..)->saveXML() // for that will break xsl:output as text, as well as omit xml decl libxml_clear_errors(); $rc = parent::transformToXml($doc); if (count(libxml_get_errors()) != 0) { throw new fXSLTProcessorException('Error in transformation', fXSLTProcessorException::TransformationFailed); } return $rc; } /** * Register an fXSLCallback object instance * * @param fXSLCallback $callback The instance of the fXSLCallback to register */ public function registerCallback(fXSLCallback $callback) { $this->initDone = FALSE; if (!$this->registered) { $this->registerPHPFunctions(); } if (!isset(self::$registry[$this->hash])) { self::$registry[$this->hash] = array(); } self::$registry[$this->hash][$callback->getNamespace()] = $callback; } /** * Static method to be called from within xsl * * Additional parameters are going to get passed on the to method called * * @param string $hash The spl_object_hash of the fXSLProcessor instance the call has been triggered in * @param string $namespace The namespace of the class instance the call is ment for * @param string $method The method to call on the instance specified by namespace * * @return string|\DomNode */ public static function callbackHook($hash, $namespace, $method) { $obj = self::$registry[$hash][$namespace]->getObject(); $params = array_slice(func_get_args(), 3); return call_user_func_array(array($obj, $method), $params); } /** * Internal helper to do the template initialisation and injection of registered objects */ private function initStylesheet() { $this->initDone = TRUE; libxml_clear_errors(); if (isset(self::$registry[$this->hash])) { foreach (self::$registry[$this->hash] as $cb) { $cb->injectCallbackCode($this->stylesheet, $this->hash); } } if (libxml_get_last_error()) { throw new fXSLTProcessorException('Error registering callbacks', fXSLTProcessorException::ImportFailed); } parent::importStylesheet($this->stylesheet); if (libxml_get_last_error()) { throw new fXSLTProcessorException('Error while importing given stylesheet', fXSLTProcessorException::ImportFailed); } } } /** * fXSLTProcessorException * * @category PHP * @package TheSeer\fXSL * @author Arne Blankerts * @access public */ class fXSLTProcessorException extends \Exception { const WrongNamespace = 1; const ImportFailed = 2; const NotCallable = 3; const UnknownInstance = 4; const TransformationFailed = 5; public function __construct($message, $code) { $errorList = libxml_get_errors(); libxml_clear_errors(); $message .= "\n\n"; foreach ($errorList as $error) { // hack, skip "attempt to load external pseudo error" if ($error->code == '1543') { continue; } if (empty($error->file)) { $message .= '[XML-STRING] '; } else { $message .= '[' . $error->file . '] '; } $message .= '[Line: ' . $error->line . ' - Column: ' . $error->column . '] '; switch ($error->level) { case LIBXML_ERR_WARNING: $message .= "Warning $error->code: "; break; case LIBXML_ERR_ERROR: $message .= "Error $error->code: "; break; case LIBXML_ERR_FATAL: $message .= "Fatal Error $error->code: "; break; } $message .= str_replace("\n", '', $error->message) . "\n"; } parent::__construct($message, $code); } } }fXSL-1.1.1/tests/000077500000000000000000000000001243570232400134725ustar00rootroot00000000000000fXSL-1.1.1/tests/_data/000077500000000000000000000000001243570232400145425ustar00rootroot00000000000000fXSL-1.1.1/tests/_data/basic.xsl000066400000000000000000000002761243570232400163600ustar00rootroot00000000000000 fXSL-1.1.1/tests/_data/broken.xsl000066400000000000000000000001031243570232400165440ustar00rootroot00000000000000 fXSL-1.1.1/tests/_data/test.xsl000066400000000000000000000010461243570232400162520ustar00rootroot00000000000000 fXSL-1.1.1/tests/fxslcallbackTest.php000066400000000000000000000006151243570232400174760ustar00rootroot00000000000000assertEquals("test:only", $callback->getNamespace()); $callback->setObject($object); $this->assertEquals($object, $callback->getObject()); } } fXSL-1.1.1/tests/fxsltprocessorTest.php000066400000000000000000000046401243570232400201470ustar00rootroot00000000000000loadStylesheetFromFile(__DIR__ . '/_data/basic.xsl'); $res = $xsl->transformToDoc($dom); $this->assertEquals('test', $res->documentElement->nodeName); } public function testLoadingStylesheetFromXML() { $dom = new \DOMDocument(); $xsl = new fXSLTProcessor(); $xsl->loadStylesheetFromXML( file_get_contents(__DIR__ . '/_data/basic.xsl')); $res = $xsl->transformToDoc($dom); $this->assertEquals('test', $res->documentElement->nodeName); } /** * @expectedException \TheSeer\fXSL\fXSLTProcessorException */ public function testLoadingInvalidStylesheetFromFileThrowsException() { $xsl = new fXSLTProcessor(); $xsl->loadStylesheetFromFile(__DIR__ . '/_data/broken.xsl'); } public function testTransform() { $tpl = new \DOMDocument(); $tpl->load(__DIR__ . '/_data/test.xsl'); $dom = new \DOMDocument(); $xsl = new fXSLTProcessor($tpl); $xsl->registerPHPFunctions("TheSeer\\fXSL\\fxsltprocessorTest::demo"); $test = new fXSLCallback('test:only', 'test'); $test->setObject($this); $xsl->registerCallback($test); $result = $xsl->transformToXml($dom); $testDoc = new \DOMDocument(); $testDoc->loadXML($result); $testXPath = new \DOMXPath($testDoc); $demos = $testXPath->evaluate("/root/demo"); /* @var $demos \DOMNodeList */ $this->assertEquals(1, $demos->length); $this->assertEquals( self::demo(), $demos->item(0)->textContent ); $roots = $testXPath->evaluate("/root/test/root"); /* @var $roots \DOMNodeList */ $this->assertEquals(1, $roots->length); $this->assertEquals( $this->bar('hallo', 'welt')->textContent, $roots->item(0)->textContent ); } public static function demo() { return 'Demo reply'; } public function bar($a, $b) { $x = new \DOMDocument(); $x->loadXML(''); $p = $x->createTextNode($a . ' -> ' . $b); $x->documentElement->appendChild($p); return $x->documentElement; } }