Diese Erweiterung für die WoltLab Suite 5.2+ erweitert selbige um eine Implementation des Shunting-yard-Algorithmus, mit dessen Hilfe sich mathematische Operationen (z.B. aus einer Option heraus) ohne Nutzung potenziell gefährlicher PHP-Funktionen ausführen lassen.
Nutzungsbeispiele:
PHP
<?php
require_once(WCF_DIR . 'lib/system/api/php-shunting-yard/autoload.php');
$equation = '3 + 4 * 2 / ( 1 - 5 ) ^ 2 ^ 3';
$result = \RR\Shunt\Parser::parse($equation);
echo $result; // 3.0001220703125
PHP
<?php
require_once(WCF_DIR . 'lib/system/api/php-shunting-yard/autoload.php');
$string = 'max(%x * 0.1 + 0.35, 2000)';
$string = str_replace('%x', 3434.133, $string);
$ctx = new \RR\Shunt\Context();
$allowedFunctions = ['ceil', 'exp', 'floor', 'fmod', 'max', 'min', 'pow']; // erlaubte PHP-Funktionen
foreach ($allowedFunctions as $fn) {
if (str_contains($string, $fn . '(')) {
$ctx->def($fn);
}
}
$result = \RR\Shunt\Parser::parse($string, $ctx);
echo $result; // 2000
Alles anzeigen
Aktuell sind keine Kundenrezensionen vorhanden. Seien Sie der Erste, der eine Rezension erstellt!
-
[Entwickler] Shunting-yard 1.2.0
-
12. Oktober 2023 -
7,92 kB
Update für WSC 6.0
-
-
[Entwickler] Shunting-yard 1.1.0
-
1. Februar 2022 -
8,62 kB
Update für PHP 7.0+ -
-
[Entwickler] Shunting-yard 1.0.2
-
11. Oktober 2021 -
8,71 kB
-