Skip to content

Commit

Permalink
On non Linux OS, resolve xsl:import in PHP to work around
Browse files Browse the repository at this point in the history
libxml/libxslt issues on these platforms.

This should fix #255, potentially fix #288
  • Loading branch information
theseer committed Mar 21, 2017
1 parent b71c43c commit bfeb05c
Show file tree
Hide file tree
Showing 13 changed files with 147 additions and 41 deletions.
27 changes: 25 additions & 2 deletions src/generator/engine/AbstractEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions templates/html/class.xsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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"
exclude-result-prefixes="pdx pdxf pu">
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">

<xsl:import href="components.xsl" />
<xsl:import href="functions.xsl" />
Expand Down
7 changes: 6 additions & 1 deletion templates/html/components.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<xsl:param name="base" select="''" />
<xsl:param name="xml" select="''" />
Expand Down
10 changes: 8 additions & 2 deletions templates/html/directory.xsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:ctx="ctx://engine/html"
xmlns:pdx="http://xml.phpdox.net/src"
xmlns:pdxf="http://xml.phpdox.net/functions"
xmlns:pdx="http://xml.phpdox.net/src">
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">

<xsl:import href="components.xsl" />
<xsl:import href="functions.xsl" />
Expand Down
60 changes: 40 additions & 20 deletions templates/html/functions.xsl
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:func="http://exslt.org/functions"
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"
xmlns:ctx="ctx://engine/html"
extension-element-prefixes="func"
exclude-result-prefixes="pdxf">
exclude-result-prefixes="idx pdx pdxf pu git ctx">

<func:function name="pdxf:link">
<xsl:param name="ctx" />
<xsl:param name="method" />
<xsl:param name="copy" />
<xsl:param name="ctx"/>
<xsl:param name="method"/>
<xsl:param name="copy"/>

<xsl:variable name="dir">
<xsl:choose>
Expand All @@ -27,50 +32,65 @@
</xsl:variable>

<xsl:variable name="withMethod">
<xsl:if test="$method != ''"><xsl:value-of select="concat('/', $method)" /></xsl:if>
<xsl:if test="$method != ''">
<xsl:value-of select="concat('/', $method)"/>
</xsl:if>
</xsl:variable>

<xsl:variable name="link">
<xsl:value-of select="concat($base, $dir, '/', translate($ctx/@full, '\', '_'), $withMethod, '.', $extension)" />
<xsl:value-of
select="concat($base, $dir, '/', translate($ctx/@full, '\', '_'), $withMethod, '.', $extension)"/>
</xsl:variable>

<xsl:variable name="text">
<xsl:choose>
<xsl:when test="$copy"><xsl:value-of select="$copy" /></xsl:when>
<xsl:otherwise><xsl:value-of select="$ctx/@name" /></xsl:otherwise>
<xsl:when test="$copy">
<xsl:value-of select="$copy"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$ctx/@name"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>

<func:result>
<xsl:choose>
<xsl:when test="$ctx/@unresolved = 'true'"><xsl:value-of select="$text" /></xsl:when>
<xsl:otherwise><a title="{$ctx/@full}" href="{$link}"><xsl:value-of select="$text" /></a></xsl:otherwise>
<xsl:when test="$ctx/@unresolved = 'true'">
<xsl:value-of select="$text"/>
</xsl:when>
<xsl:otherwise>
<a title="{$ctx/@full}" href="{$link}">
<xsl:value-of select="$text"/>
</a>
</xsl:otherwise>
</xsl:choose>
</func:result>
</func:function>

<func:function name="pdxf:nl2br">
<xsl:param name="string"/>
<xsl:variable name="format">
<xsl:param name="string"/>
<xsl:variable name="format">
<xsl:value-of select="normalize-space(substring-before($string,'&#10;'))"/>
<xsl:choose>
<xsl:when test="contains($string,'&#10;')">
<br />
<xsl:copy-of select="pdxf:nl2br(substring-after($string,'&#10;'))" />
<br/>
<xsl:copy-of select="pdxf:nl2br(substring-after($string,'&#10;'))"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<func:result><xsl:copy-of select="$format" /></func:result>
</xsl:variable>
<func:result>
<xsl:copy-of select="$format"/>
</func:result>
</func:function>

<func:function name="pdxf:format-number">
<xsl:param name="value"/>
<xsl:param name="format">0.##</xsl:param>
<func:result>
<xsl:choose>
<func:result>
<xsl:choose>
<xsl:when test="string(number($value))='NaN'">
<xsl:value-of select="format-number(0, $format)"/>
</xsl:when>
Expand All @@ -82,7 +102,7 @@
</func:function>

<func:function name="pdxf:filesize">
<xsl:param name="bytes" />
<xsl:param name="bytes"/>

<func:result>
<xsl:choose>
Expand Down
10 changes: 8 additions & 2 deletions templates/html/index.xsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:git="http://xml.phpdox.net/gitlog"
xmlns:pdx="http://xml.phpdox.net/src"
xmlns:pdxf="http://xml.phpdox.net/functions">
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">

<xsl:import href="functions.xsl"/>
<xsl:import href="components.xsl" />
Expand Down
9 changes: 7 additions & 2 deletions templates/html/interface.xsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:pdx="http://xml.phpdox.net/src"
xmlns:idx="http://xml.phpdox.net/src"
xmlns:pdxf="http://xml.phpdox.net/functions"
exclude-result-prefixes="idx 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">

<xsl:import href="components.xsl" />
<xsl:import href="functions.xsl" />
Expand Down
7 changes: 6 additions & 1 deletion templates/html/method.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<xsl:import href="components.xsl" />
<xsl:import href="functions.xsl" />
Expand Down
10 changes: 8 additions & 2 deletions templates/html/namespaces.xsl
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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"
exclude-result-prefixes="idx">
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">

<xsl:import href="components.xsl" />

<xsl:output method="xml" indent="yes" encoding="UTF-8" doctype-system="about:legacy-compat" />

<xsl:template match="/">
Expand Down
9 changes: 8 additions & 1 deletion templates/html/reports/index.xsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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"
xmlns:pdx="http://xml.phpdox.net/src">
xmlns:ctx="ctx://engine/html"
extension-element-prefixes="func"
exclude-result-prefixes="idx pdx pdxf pu git ctx">

<xsl:import href="../components.xsl" />

Expand Down
13 changes: 10 additions & 3 deletions templates/html/source.xsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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"
xmlns:ctx="ctx://engine/html"
xmlns:token="http://xml.phpdox.net/token"
xmlns:src="http://xml.phpdox.net/src"
xmlns:pu="http://schema.phpunit.de/coverage/1.0"
xmlns="http://www.w3.org/1999/xhtml"
exclude-result-prefixes="token src">
extension-element-prefixes="func"
exclude-result-prefixes="idx pdx pdxf pu git ctx token src">

<xsl:import href="components.xsl" />
<xsl:import href="functions.xsl" />
Expand Down
8 changes: 7 additions & 1 deletion templates/html/synopsis.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -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">

<xsl:variable name="type">
<xsl:choose>
Expand Down
10 changes: 8 additions & 2 deletions templates/html/units.xsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:idx="http://xml.phpdox.net/src"
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="idx pu">
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">

<xsl:import href="components.xsl" />

Expand Down

0 comments on commit bfeb05c

Please sign in to comment.