-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
33 lines (25 loc) · 845 Bytes
/
index.php
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
<?php
require_once '../src/IntervalCycler.php';
header('Content-Type: application/json');
$method = $_SERVER['REQUEST_METHOD'];
$cycler = new IntervalCycler();
if ($method === 'POST') {
$action = $_POST['action'] ?? '';
if ($action === 'process') {
$row = $_POST['row'] ?? '';
if (empty($row)) {
echo json_encode(['error' => 'No pitch data provided']);
exit;
}
$pitches = array_map('intval', explode(' ', $row));
$result = $cycler->process($pitches);
echo json_encode(['success' => true, 'data' => $result]);
exit;
}
if ($action === 'random') {
$randomRow = $cycler->generateRandomPitches();
echo json_encode(['success' => true, 'data' => $randomRow]);
exit;
}
}
echo json_encode(['error' => 'Invalid request']);