-
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.
[RFC] Improve callbacks in ext/dom and ext/xsl (#12627)
- Loading branch information
Showing
38 changed files
with
1,668 additions
and
521 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
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
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
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
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,88 @@ | ||
--TEST-- | ||
registerPHPFunctions() with callables - legit cases | ||
--EXTENSIONS-- | ||
dom | ||
--FILE-- | ||
<?php | ||
|
||
class MyClass { | ||
public static function dump(string $var) { | ||
var_dump($var); | ||
} | ||
} | ||
|
||
class MyDOMXPath extends DOMXPath { | ||
public function registerCycle() { | ||
$this->registerPhpFunctions(["cycle" => array($this, "dummy")]); | ||
} | ||
|
||
public function dummy(string $var) { | ||
echo "dummy: $var\n"; | ||
} | ||
} | ||
|
||
$doc = new DOMDocument(); | ||
$doc->loadHTML('<a href="https://php.net">hello</a>'); | ||
|
||
echo "--- Legit cases: none ---\n"; | ||
|
||
$xpath = new DOMXPath($doc); | ||
$xpath->registerNamespace("php", "http://php.net/xpath"); | ||
try { | ||
$xpath->evaluate("//a[php:function('var_dump', string(@href))]"); | ||
} catch (Error $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
echo "--- Legit cases: all ---\n"; | ||
|
||
$xpath->registerPHPFunctions(null); | ||
$xpath->evaluate("//a[php:function('var_dump', string(@href))]"); | ||
$xpath->evaluate("//a[php:function('MyClass::dump', string(@href))]"); | ||
|
||
echo "--- Legit cases: set ---\n"; | ||
|
||
$xpath = new DOMXPath($doc); | ||
$xpath->registerNamespace("php", "http://php.net/xpath"); | ||
$xpath->registerPhpFunctions([]); | ||
$xpath->registerPHPFunctions(["xyz" => MyClass::dump(...), "mydump" => function (string $x) { | ||
var_dump($x); | ||
}]); | ||
$xpath->registerPhpFunctions(str_repeat("var_dump", mt_rand(1, 1) /* defeat SCCP */)); | ||
$xpath->evaluate("//a[php:function('mydump', string(@href))]"); | ||
$xpath->evaluate("//a[php:function('xyz', string(@href))]"); | ||
$xpath->evaluate("//a[php:function('var_dump', string(@href))]"); | ||
try { | ||
$xpath->evaluate("//a[php:function('notinset', string(@href))]"); | ||
} catch (Throwable $e) { | ||
echo $e->getMessage(), "\n"; | ||
} | ||
|
||
echo "--- Legit cases: set with cycle ---\n"; | ||
|
||
$xpath = new MyDOMXPath($doc); | ||
$xpath->registerNamespace("php", "http://php.net/xpath"); | ||
$xpath->registerCycle(); | ||
$xpath->evaluate("//a[php:function('cycle', string(@href))]"); | ||
|
||
echo "--- Legit cases: reset to null ---\n"; | ||
|
||
$xpath->registerPhpFunctions(null); | ||
$xpath->evaluate("//a[php:function('var_dump', string(@href))]"); | ||
|
||
?> | ||
--EXPECT-- | ||
--- Legit cases: none --- | ||
No callbacks were registered | ||
--- Legit cases: all --- | ||
string(15) "https://php.net" | ||
string(15) "https://php.net" | ||
--- Legit cases: set --- | ||
string(15) "https://php.net" | ||
string(15) "https://php.net" | ||
string(15) "https://php.net" | ||
No callback handler "notinset" registered | ||
--- Legit cases: set with cycle --- | ||
dummy: https://php.net | ||
--- Legit cases: reset to null --- | ||
string(15) "https://php.net" |
Oops, something went wrong.