-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prototype XSLTProcessor::transformToStream()
- Loading branch information
Showing
6 changed files
with
185 additions
and
1 deletion.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,38 @@ | ||
--TEST-- | ||
XSLTProcessor::transformToStream() function - normal | ||
--EXTENSIONS-- | ||
xsl | ||
--FILE-- | ||
<?php | ||
include("prepare.inc"); | ||
$proc->importStylesheet($xsl); | ||
|
||
$stream = fopen('php://output', 'w'); | ||
$written = $proc->transformToStream($dom, $stream); | ||
fclose($stream); | ||
|
||
echo "\n"; | ||
var_dump($written); | ||
|
||
$stream = fopen('php://output', 'w'); | ||
$written = $proc->transformToStream($dom, $stream, 'iso-8859-1'); | ||
fclose($stream); | ||
|
||
echo "\n"; | ||
var_dump($written); | ||
?> | ||
--EXPECT-- | ||
<?xml version="1.0" encoding="iso-8859-1"?> | ||
<html><body>bar | ||
a1 b1 c1 <br/> | ||
a2 c2 <br/> | ||
ä3 b3 c3 <br/> | ||
</body></html> | ||
int(120) | ||
<?xml version="1.0" encoding="iso-8859-1"?> | ||
<html><body>bar | ||
a1 b1 c1 <br/> | ||
a2 c2 <br/> | ||
ä3 b3 c3 <br/> | ||
</body></html> | ||
int(119) |
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,52 @@ | ||
--TEST-- | ||
XSLTProcessor::transformToStream() function - broken stream | ||
--EXTENSIONS-- | ||
xsl | ||
--FILE-- | ||
<?php | ||
class MyStream { | ||
public $context; | ||
private bool $first = true; | ||
|
||
public function stream_write(string $data): int { | ||
if ($this->first) { | ||
$this->first = false; | ||
var_dump($data); | ||
} | ||
throw new Error("broken"); | ||
} | ||
|
||
public function stream_open(string $path, string $mode, int $options, ?string &$opened_path) { | ||
return true; | ||
} | ||
|
||
public function stream_close(): void { | ||
} | ||
|
||
public function stream_eof(): bool { | ||
return !$this->first; | ||
} | ||
} | ||
|
||
stream_wrapper_register("foo", MyStream::class); | ||
|
||
include("prepare.inc"); | ||
$proc->importStylesheet($xsl); | ||
|
||
$stream = fopen('foo://', 'w'); | ||
stream_set_chunk_size($stream, 4); | ||
$written = $proc->transformToStream($dom, $stream); | ||
fclose($stream); | ||
|
||
echo "\n"; | ||
var_dump($written); | ||
?> | ||
--EXPECTF-- | ||
string(4) "<?xm" | ||
|
||
Fatal error: Uncaught Error: broken in %s:%d | ||
Stack trace: | ||
#0 [internal function]: MyStream->stream_write('<?xm') | ||
#1 %s(%d): XSLTProcessor->transformToStream(Object(DOMDocument), Resource id #%d) | ||
#2 {main} | ||
thrown in %s on line %d |
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,19 @@ | ||
--TEST-- | ||
XSLTProcessor::transformToStream() function - errors | ||
--EXTENSIONS-- | ||
xsl | ||
--FILE-- | ||
<?php | ||
include("prepare.inc"); | ||
$proc->importStylesheet($xsl); | ||
|
||
$stream = fopen('php://output', 'w'); | ||
try { | ||
$proc->transformToStream($dom, $stream, 'nope'); | ||
} catch (ValueError $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
fclose($stream); | ||
?> | ||
--EXPECT-- | ||
XSLTProcessor::transformToStream(): Argument #3 ($encoding) is not a valid document encoding |
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