Skip to content

Commit

Permalink
Use SHA1 to generate filename.
Browse files Browse the repository at this point in the history
Replace the '\' to '_' class FQN transformation by SHA1 to prevent issue with filename being too long.

Close theseer#351
  • Loading branch information
MacFJA committed Oct 6, 2019
1 parent ed98080 commit 28aadd3
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/collector/project/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ private function saveUnit(array $map, array $reportUnits, AbstractUnitObject $un
ProjectException::UnitNotFoundInIndex
);
}
$name = \str_replace('\\', '_', $unit->getName());
$name = sha1($unit->getName());
$dom = $unit->export();
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
Expand Down
4 changes: 3 additions & 1 deletion src/generator/engine/html/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ protected function getXSLTProcessor($template) {
$xsl->setParameter('', 'project', $this->projectNode->getAttribute('name'));
}

$xsl->registerPHPFunctions('sha1');

return $xsl;
}

Expand Down Expand Up @@ -256,7 +258,7 @@ private function genericMethodBuild(fDOMDocument $ctx, $target, $unitName, $meth
}

private function classNameToFileName($class, $method = null) {
$name = \str_replace('\\', '_', $class);
$name = sha1($class);

if ($method !== null) {
$name .= '/' . $method;
Expand Down
3 changes: 2 additions & 1 deletion src/generator/engine/xml/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ public function handle(AbstractEvent $event): void {
}
}
$dom = $ctx->asDom();
$fname = sha1($dom->documentElement->getAttribute('full'));
$this->saveDomDocument(
$dom,
$this->outputDir . '/' . $path . '/' . \str_replace('\\', '_', $dom->documentElement->getAttribute('full')) . '.xml'
$this->outputDir . '/' . $path . '/' . $fname . '.xml'
);
}

Expand Down
5 changes: 3 additions & 2 deletions templates/html/functions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
xmlns:idx="http://xml.phpdox.net/src"
xmlns:git="http://xml.phpdox.net/gitlog"
xmlns:ctx="ctx://engine/html"
xmlns:php="http://php.net/xsl"
extension-element-prefixes="func"
exclude-result-prefixes="idx pdx pdxf pu git ctx">
exclude-result-prefixes="idx pdx pdxf pu git ctx php">

<func:function name="pdxf:link">
<xsl:param name="ctx"/>
Expand Down Expand Up @@ -39,7 +40,7 @@

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

<xsl:variable name="text">
Expand Down
9 changes: 7 additions & 2 deletions templates/html/units.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
xmlns:idx="http://xml.phpdox.net/src"
xmlns:git="http://xml.phpdox.net/gitlog"
xmlns:ctx="ctx://engine/html"
xmlns:php="http://php.net/xsl"
extension-element-prefixes="func"
exclude-result-prefixes="idx pdx pdxf pu git ctx">
exclude-result-prefixes="idx pdx pdxf pu git ctx php">

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

Expand Down Expand Up @@ -49,11 +50,15 @@
<xsl:for-each select="*[local-name() = $mode]">
<xsl:sort select="@name" order="ascending" />

<xsl:variable name="fullclass"><xsl:choose>
<xsl:when test="../@name != ''"><xsl:value-of select="concat(../@name, '\')" /></xsl:when>
<xsl:otherwise/>
</xsl:choose><xsl:value-of select="@name" /></xsl:variable>
<xsl:variable name="link"><xsl:choose>
<xsl:when test="local-name(.) = 'class'">classes</xsl:when>
<xsl:when test="local-name(.) = 'interface'">interfaces</xsl:when>
<xsl:otherwise>traits</xsl:otherwise>
</xsl:choose>/<xsl:value-of select="translate(../@name, '\', '_')" /><xsl:if test="not(../@name = '')">_</xsl:if><xsl:value-of select="@name" />.<xsl:value-of select="$extension" /></xsl:variable>
</xsl:choose>/<xsl:value-of select="php:function('sha1', $fullclass)" />.<xsl:value-of select="$extension" /></xsl:variable>
<tr>
<td><a href="{$link}"><xsl:value-of select="@name" /></a></td>
<td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Lorem\ipsum\dolor\sit\amet\consectetur\adipiscing\elit\Phasellus\aliquet\lacus\vel\lectus\vehicula\facilisis\quis\eu\ex\Duis\dignissim;

class NequePorroQuisquamEstQuiDoloremIpsumQuiaDolorSitAmetConsecteturAdipisciVelit
{
public $var = 'hello';
const A_PLACE = 'world';

function f() {
// ...
}
}
8 changes: 8 additions & 0 deletions tests/data/issue351/src/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

class NoNamespace {
function foo()
{
// ...
}
}
15 changes: 15 additions & 0 deletions tests/data/issue351/test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<phpdox xmlns="http://xml.phpdox.net/config" silent="false">

<project name="phpDox-issue" source="${basedir}/src" workdir="${basedir}/xml">

<collector publiconly="false" backend="parser" />

<generator output="${basedir}/docs">
<build engine="html" enabled="true" output="html" />
<build engine="xml" enabled="true" output="xml" />
</generator>

</project>

</phpdox>

0 comments on commit 28aadd3

Please sign in to comment.