From bfeb05c2cec28cc06fb46f0c3080c74ebde6593c Mon Sep 17 00:00:00 2001 From: Arne Blankerts Date: Tue, 21 Mar 2017 17:38:25 +0100 Subject: [PATCH] On non Linux OS, resolve xsl:import in PHP to work around libxml/libxslt issues on these platforms. This should fix #255, potentially fix #288 --- src/generator/engine/AbstractEngine.php | 27 ++++++++++- templates/html/class.xsl | 8 +++- templates/html/components.xsl | 7 ++- templates/html/directory.xsl | 10 ++++- templates/html/functions.xsl | 60 ++++++++++++++++--------- templates/html/index.xsl | 10 ++++- templates/html/interface.xsl | 9 +++- templates/html/method.xsl | 7 ++- templates/html/namespaces.xsl | 10 ++++- templates/html/reports/index.xsl | 9 +++- templates/html/source.xsl | 13 ++++-- templates/html/synopsis.xsl | 8 +++- templates/html/units.xsl | 10 ++++- 13 files changed, 147 insertions(+), 41 deletions(-) diff --git a/src/generator/engine/AbstractEngine.php b/src/generator/engine/AbstractEngine.php index 23c5c80b..318dc284 100644 --- a/src/generator/engine/AbstractEngine.php +++ b/src/generator/engine/AbstractEngine.php @@ -47,8 +47,10 @@ abstract class AbstractEngine implements EngineInterface { protected function getXSLTProcessor($template) { $tpl = new fDomDocument(); $tpl->load($template); - $xsl = new fXSLTProcessor($tpl); - return $xsl; + if (stripos(PHP_OS, 'Linux') !== 0) { + $this->resolveImports($tpl); + } + return new fXSLTProcessor($tpl); } protected function clearDirectory($path) { @@ -94,6 +96,27 @@ protected function copyStatic($path, $dest, $recursive = true) { } } + private function resolveImports(fDOMDocument $doc) { + $doc->registerNamespace('xsl', 'http://www.w3.org/1999/XSL/Transform'); + $baseDir = dirname($doc->documentURI); + $baseElement = $doc->documentElement; + foreach($doc->query('/xsl:stylesheet/xsl:import') as $importNode) { + /** @var $importNode \DOMElement */ + $import = new fDOMDocument(); + $import->load($baseDir . '/' . $importNode->getAttribute('href')); + + $newParent = $importNode->parentNode; + foreach ($import->documentElement->childNodes as $child) { + if ($child->localName === 'output') { + continue; + } + $importedChild = $doc->importNode($child, true); + $newParent->insertBefore($importedChild, $importNode); + } + $newParent->removeChild($importNode); + } + } + } class EngineException extends \Exception { diff --git a/templates/html/class.xsl b/templates/html/class.xsl index 2a8c5a69..8fe48c57 100644 --- a/templates/html/class.xsl +++ b/templates/html/class.xsl @@ -1,10 +1,14 @@ - + xmlns:func="http://exslt.org/functions" + xmlns:idx="http://xml.phpdox.net/src" + xmlns:git="http://xml.phpdox.net/gitlog" + xmlns:ctx="ctx://engine/html" + extension-element-prefixes="func" + exclude-result-prefixes="idx pdx pdxf pu git ctx"> diff --git a/templates/html/components.xsl b/templates/html/components.xsl index 009ed03a..6bf1b7e2 100644 --- a/templates/html/components.xsl +++ b/templates/html/components.xsl @@ -2,8 +2,13 @@ xmlns="http://www.w3.org/1999/xhtml" xmlns:pdx="http://xml.phpdox.net/src" xmlns:pdxf="http://xml.phpdox.net/functions" + xmlns:pu="http://schema.phpunit.de/coverage/1.0" + xmlns:func="http://exslt.org/functions" + xmlns:idx="http://xml.phpdox.net/src" xmlns:git="http://xml.phpdox.net/gitlog" - exclude-result-prefixes="pdx pdxf git"> + xmlns:ctx="ctx://engine/html" + extension-element-prefixes="func" + exclude-result-prefixes="idx pdx pdxf pu git ctx"> diff --git a/templates/html/directory.xsl b/templates/html/directory.xsl index d49fe7f5..cd4564cf 100644 --- a/templates/html/directory.xsl +++ b/templates/html/directory.xsl @@ -1,8 +1,14 @@ + xmlns:pu="http://schema.phpunit.de/coverage/1.0" + xmlns:func="http://exslt.org/functions" + xmlns:idx="http://xml.phpdox.net/src" + xmlns:git="http://xml.phpdox.net/gitlog" + xmlns:ctx="ctx://engine/html" + extension-element-prefixes="func" + exclude-result-prefixes="idx pdx pdxf pu git ctx"> diff --git a/templates/html/functions.xsl b/templates/html/functions.xsl index 7ba3f55e..2916e364 100644 --- a/templates/html/functions.xsl +++ b/templates/html/functions.xsl @@ -1,14 +1,19 @@ + exclude-result-prefixes="idx pdx pdxf pu git ctx"> - - - + + + @@ -27,50 +32,65 @@ - + + + - + - - + + + + + + - - + + + + + + + + - - + + -
- +
+
-
- +
+ + +
0.## - - + + @@ -82,7 +102,7 @@ - + diff --git a/templates/html/index.xsl b/templates/html/index.xsl index 6205e028..acfd3e16 100644 --- a/templates/html/index.xsl +++ b/templates/html/index.xsl @@ -1,8 +1,14 @@ + xmlns:pdxf="http://xml.phpdox.net/functions" + xmlns:pu="http://schema.phpunit.de/coverage/1.0" + xmlns:func="http://exslt.org/functions" + xmlns:idx="http://xml.phpdox.net/src" + xmlns:git="http://xml.phpdox.net/gitlog" + xmlns:ctx="ctx://engine/html" + extension-element-prefixes="func" + exclude-result-prefixes="idx pdx pdxf pu git ctx"> diff --git a/templates/html/interface.xsl b/templates/html/interface.xsl index bc2fa191..5d8ed0a6 100644 --- a/templates/html/interface.xsl +++ b/templates/html/interface.xsl @@ -1,9 +1,14 @@ + xmlns:pu="http://schema.phpunit.de/coverage/1.0" + xmlns:func="http://exslt.org/functions" + xmlns:idx="http://xml.phpdox.net/src" + xmlns:git="http://xml.phpdox.net/gitlog" + xmlns:ctx="ctx://engine/html" + extension-element-prefixes="func" + exclude-result-prefixes="idx pdx pdxf pu git ctx"> diff --git a/templates/html/method.xsl b/templates/html/method.xsl index 739b7ea5..5a2d8f60 100644 --- a/templates/html/method.xsl +++ b/templates/html/method.xsl @@ -3,7 +3,12 @@ xmlns:pdx="http://xml.phpdox.net/src" xmlns:pdxf="http://xml.phpdox.net/functions" xmlns:pu="http://schema.phpunit.de/coverage/1.0" - exclude-result-prefixes="pdx pdxf"> + xmlns:func="http://exslt.org/functions" + xmlns:idx="http://xml.phpdox.net/src" + xmlns:git="http://xml.phpdox.net/gitlog" + xmlns:ctx="ctx://engine/html" + extension-element-prefixes="func" + exclude-result-prefixes="idx pdx pdxf pu git ctx"> diff --git a/templates/html/namespaces.xsl b/templates/html/namespaces.xsl index a2af458c..109039ee 100644 --- a/templates/html/namespaces.xsl +++ b/templates/html/namespaces.xsl @@ -1,10 +1,16 @@ + xmlns:git="http://xml.phpdox.net/gitlog" + xmlns:ctx="ctx://engine/html" + extension-element-prefixes="func" + exclude-result-prefixes="idx pdx pdxf pu git ctx"> - diff --git a/templates/html/reports/index.xsl b/templates/html/reports/index.xsl index ef4fe299..c666a26c 100644 --- a/templates/html/reports/index.xsl +++ b/templates/html/reports/index.xsl @@ -1,7 +1,14 @@ + xmlns:ctx="ctx://engine/html" + extension-element-prefixes="func" + exclude-result-prefixes="idx pdx pdxf pu git ctx"> diff --git a/templates/html/source.xsl b/templates/html/source.xsl index 0baf539f..bd1c5ea1 100644 --- a/templates/html/source.xsl +++ b/templates/html/source.xsl @@ -1,9 +1,16 @@ + extension-element-prefixes="func" + exclude-result-prefixes="idx pdx pdxf pu git ctx token src"> diff --git a/templates/html/synopsis.xsl b/templates/html/synopsis.xsl index dcec8745..08106a3b 100644 --- a/templates/html/synopsis.xsl +++ b/templates/html/synopsis.xsl @@ -2,7 +2,13 @@ xmlns="http://www.w3.org/1999/xhtml" xmlns:pdx="http://xml.phpdox.net/src" xmlns:pdxf="http://xml.phpdox.net/functions" - exclude-result-prefixes="pdx pdxf"> + xmlns:pu="http://schema.phpunit.de/coverage/1.0" + xmlns:func="http://exslt.org/functions" + xmlns:idx="http://xml.phpdox.net/src" + xmlns:git="http://xml.phpdox.net/gitlog" + xmlns:ctx="ctx://engine/html" + extension-element-prefixes="func" + exclude-result-prefixes="idx pdx pdxf pu git ctx"> diff --git a/templates/html/units.xsl b/templates/html/units.xsl index 0a9e55a2..cf2d8611 100644 --- a/templates/html/units.xsl +++ b/templates/html/units.xsl @@ -1,8 +1,14 @@ + xmlns:func="http://exslt.org/functions" + xmlns:idx="http://xml.phpdox.net/src" + xmlns:git="http://xml.phpdox.net/gitlog" + xmlns:ctx="ctx://engine/html" + extension-element-prefixes="func" + exclude-result-prefixes="idx pdx pdxf pu git ctx">