Repository navigation
Expand file tree
/
Copy pathautoload.php
More file actions
89 lines (77 loc) · 2.97 KB
/
Copy pathautoload.php
File metadata and controls
89 lines (77 loc) · 2.97 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/*
* Copyright 2026 M. Bryce Hudson
* SPDX-License-Identifier: Apache-2.0
*/
// Router Module Autoloader
// Include this file to load all router classes
spl_autoload_register(function($class) {
// Project namespace prefix
$prefix = 'Src\\';
// Base directory for the classes
$baseDir = __DIR__ . '/src/';
// Check if the class uses the prefix
if (strncmp($prefix, $class, strlen($prefix)) !== 0) {
// No, move to next autoload
return;
}
// Get the relative class name
$relativeClass = substr($class, strlen($prefix));
// Replace namespace separators with directory separators and append .php
$file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';
// If the file exists, require it
if (file_exists($file)) {
require $file;
}
});
// A hand-off that failed gets another go here.
//
// An install that could not replace the file it was running from leaves
// storage/updates/install.json on "finishing". The installer that got there is
// the copy being replaced, so on a host where THAT copy cannot find the PHP CLI
// nothing ever retried: the entry script waited as .router-new-index.php, the app
// reported the new version, and a human had to run install-update.php --finish.
//
// This file is one of the ones an install replaces, which makes it the right
// place to try again: by the next request, Src\Install on disk is the new one,
// with a phpCli() that can actually find PHP. One stat on a normal request, and
// a failure here can never break the request it is repairing after.
if (PHP_SAPI !== 'cli' && is_file(__DIR__ . '/storage/updates/install.json')) {
try {
\Src\Install::resume();
} catch (\Throwable $e) {
// Silence: the request still has to answer.
}
}
// A storage/ this request cannot write is not a slow install. It is a copy
// where every save is dropped -- a settings toggle snaps back, a session file
// is never made, and an agent's turn can look like a model thinking forever --
// so the refusal has to come before the request does any work, and it has to
// name the command that fixes it. See Src\Storage for the probe and the exact
// line; the CLI and the installer are exempt there, on purpose.
\Src\Storage::guard();
// Helper functions
function jsonResponse($data, $status = 200) {
http_response_code($status);
header('Content-Type: application/json');
echo json_encode($data);
exit;
}
function getConfig() {
$configFile = __DIR__ . '/storage/config.json';
if (file_exists($configFile)) {
return json_decode(file_get_contents($configFile), true);
}
return [
'theme' => 'neon',
'sounds_enabled' => true,
'auto_scroll' => true,
'code_isolation' => true,
'session_timeout' => 86400
];
}
function saveConfig($config) {
$configFile = __DIR__ . '/storage/config.json';
return file_put_contents($configFile, json_encode($config, JSON_PRETTY_PRINT));
}
?>