-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add transformation exception, with previous errors based on libxml errors * reset error level to previous state, instead of leaving it to true * style
- Loading branch information
1 parent
70d40a6
commit 3ffa879
Showing
4 changed files
with
109 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Genkgo\Xsl\Exception; | ||
|
||
final class TransformationException extends \Exception | ||
{ | ||
public static function fromLibxmlErrorList(array $errors): self | ||
{ | ||
if ($errors === []) { | ||
throw new \InvalidArgumentException('Cannot create exception while there are no libxml errors'); | ||
} | ||
|
||
$exceptions = []; | ||
while ($errors !== []) { | ||
/** @var \LibXMLError $error */ | ||
$error = \array_shift($errors); | ||
$previous = isset($exceptions[0]) ? $exceptions[0] : null; | ||
$exception = new self($error->message, 0, $previous); | ||
$exception->file = $error->file; | ||
$exception->code = $error->code; | ||
$exception->line = $error->line; | ||
$exceptions[] = $exception; | ||
} | ||
|
||
return new self('Transformation failed: ' . $exceptions[0]->message, 0, $exceptions[0]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Genkgo\Xsl\Integration; | ||
|
||
use DOMDocument; | ||
use Genkgo\Xsl\AbstractTestCase; | ||
use Genkgo\Xsl\Cache\NullCache; | ||
use Genkgo\Xsl\Exception\TransformationException; | ||
use Genkgo\Xsl\XsltProcessor; | ||
|
||
final class ExceptionTest extends AbstractTestCase | ||
{ | ||
public function testException() | ||
{ | ||
$this->expectException(TransformationException::class); | ||
|
||
$xslDoc = new DOMDocument(); | ||
$xslDoc->loadXML((string)\file_get_contents('Stubs/invalid-stylesheet.xsl')); | ||
|
||
$xmlDoc = new DOMDocument(); | ||
$xmlDoc->load('Stubs/collection.xml'); | ||
|
||
$transpiler = new XsltProcessor(new NullCache()); | ||
$transpiler->importStylesheet($xslDoc); | ||
$transpiler->transformToXML($xmlDoc); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1"> | ||
<xsl:variable match="/">test</xsl:variable> | ||
</xsl:stylesheet> |