Skip to content

Commit

Permalink
php 8.1 compat (#34)
Browse files Browse the repository at this point in the history
* more php 8.1 compat

* drop php 7.4
  • Loading branch information
frederikbosch authored Nov 8, 2022
1 parent d75572f commit a575600
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/code_checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: ['7.4', '8.0', '8.1']
php: ['8.0', '8.1']

name: PHP ${{ matrix.php }} tests
steps:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name" : "genkgo/xsl",
"description": "XSL 2.0 Transpiler in PHP",
"require" : {
"php" : "^7.4 || ~8.0.0 || ~8.1.0",
"php" : "~8.0.0 || ~8.1.0",
"ext-json" : "*",
"ext-libxml" : "*",
"ext-xsl" : "*",
Expand Down
30 changes: 12 additions & 18 deletions src/XsltProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ public function excludeAllPrefixes(): void
$this->excludeAllNamespaces = true;
}

/**
* @param object $stylesheet
*/
public function importStyleSheet($stylesheet)
public function importStylesheet(object $stylesheet): bool
{
$this->styleSheet = $stylesheet;
return true;
}

/**
Expand Down Expand Up @@ -91,23 +89,21 @@ function () use ($doc, $styleSheet, $transpiler):? string {
}

/**
* @param \DOMDocument $doc
* @param string|null $returnClass
* @return \DOMDocument
* @param object|\DOMDocument $document
*/
public function transformToDoc($doc, ?string $returnClass = null):? \DOMDocument
public function transformToDoc(object $document, ?string $returnClass = null): \DOMDocument|false
{
$styleSheet = $this->styleSheetToDomDocument();

$transpiler = $this->createTranspiler($styleSheet);

return $this->catchLibXmlErrorThrowTransformException(
function () use ($doc, $styleSheet, $transpiler):? \DOMDocument {
function () use ($document, $returnClass, $styleSheet, $transpiler):? \DOMDocument {
parent::importStylesheet($this->getTranspiledStyleSheet($transpiler, $styleSheet));
$this->throwOnLibxmlError();

return $transpiler->transform(function () use ($doc) {
$result = parent::transformToDoc($doc);
return $transpiler->transform(function () use ($document, $returnClass) {
$result = parent::transformToDoc($document, $returnClass);
$this->throwOnLibxmlError();
return $result;
});
Expand All @@ -116,22 +112,20 @@ function () use ($doc, $styleSheet, $transpiler):? \DOMDocument {
}

/**
* @param \DOMDocument|\SimpleXMLElement $doc
* @param string $uri
* @return int
* @param object|\DOMDocument|\SimpleXMLElement $document
*/
public function transformToUri($doc, $uri):? int
public function transformToUri(object $document, string $uri): int
{
$styleSheet = $this->styleSheetToDomDocument();
$transpiler = $this->createTranspiler($styleSheet);

return $this->catchLibXmlErrorThrowTransformException(
function () use ($doc, $uri, $styleSheet, $transpiler):? int {
function () use ($document, $uri, $styleSheet, $transpiler):? int {
parent::importStylesheet($this->getTranspiledStyleSheet($transpiler, $styleSheet));
$this->throwOnLibxmlError();

return $transpiler->transform(function () use ($doc, $uri) {
$result = parent::transformToUri($doc, $uri);
return $transpiler->transform(function () use ($document, $uri) {
$result = parent::transformToUri($document, $uri);
$this->throwOnLibxmlError();
return $result;
});
Expand Down
1 change: 1 addition & 0 deletions test/Integration/ProcessXslt1DocumentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public function testTransformToDoc(): void

$transpiler = new XsltProcessor(new NullCache());
$transpiler->importStylesheet($xslDoc);
/** @var DOMDocument $transpilerResult */
$transpilerResult = $transpiler->transformToDoc($xmlDoc);

$this->assertEquals($nativeResult->saveXML(), $transpilerResult->saveXML());
Expand Down

0 comments on commit a575600

Please sign in to comment.