-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-action-handler.php
More file actions
42 lines (35 loc) · 1.22 KB
/
test-action-handler.php
File metadata and controls
42 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
require_once dirname(__DIR__) . '/bootstrap.php';
// This file will handle AJAX requests for testing
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$input = json_decode(file_get_contents('php://input'), true);
if ($input && isset($input['component']) && isset($input['action'])) {
$instanceId = $input['component'];
$action = $input['action'];
// Extract component name from instance ID
$lastUnderscore = strrpos($instanceId, '_');
if ($lastUnderscore !== false) {
$componentName = substr($instanceId, 0, $lastUnderscore);
} else {
$componentName = $instanceId;
}
echo "Component: $componentName\n";
echo "Instance: $instanceId\n";
echo "Action: $action\n";
try {
$result = nova_action($componentName, $instanceId, $action, []);
echo "Result: " . $result;
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
exit;
}
}
// Register component
component('test-counter', function ($c) {
$c->state(fn() => ['count' => 0]);
$c->actions(['increment' => fn(&$s) => $s['count']++]);
$c->view(fn($s) => "<div>Count: {$s->count}</div>");
});
$instanceId = 'test-counter_' . uniqid();
echo nova('test-counter', ['_instance' => $instanceId]);