eval.php (1248B)
1 <?php 2 declare(strict_types=1); 3 require __DIR__.'/../src/common.php'; 4 use Arboricx\Library; 5 use function Arboricx\{readBundle, render}; 6 header('Content-Type: text/plain; charset=utf-8'); 7 try { 8 if (!isset($_FILES['bundle']) || $_FILES['bundle']['error'] !== UPLOAD_ERR_OK) throw new RuntimeException('Bundle upload failed'); 9 $name = $_POST['export'] ?? ''; 10 if ($name === '') throw new RuntimeException('Export name is required'); 11 $ctx = (new Library())->context(); 12 try { 13 $term = $ctx->loadBundle(readBundle($_FILES['bundle']['tmp_name']), $name); 14 for ($i = 0; $i < 5; $i++) { 15 $text = $_POST["arg$i"] ?? ''; 16 if ($text !== '') { 17 $argument = $ctx->string($text); 18 $next = $ctx->apply($term, $argument); 19 $ctx->release($term); $ctx->release($argument); $term = $next; 20 } 21 } 22 // Uploaded bundles are evaluated as pure trees. Native IO is available 23 // only to explicitly trusted embedding applications through runIO(). 24 echo render($ctx, $term, $_POST['format'] ?? 'string'); 25 } finally { $ctx->close(); } 26 } catch (Throwable $error) { 27 http_response_code(400); 28 echo 'Error: '.$error->getMessage(); 29 }