Skip to content

Commit 6a09486

Browse files
"Added subdomain autoloader crap and config for Spindle's soul-sucking framework."
1 parent 2fc2584 commit 6a09486

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
<?php
2+
/*
3+
* Spindle CMS
4+
* Copyright (c) 2025. All rights reserved.
5+
*
6+
* This file is part of the Spindle CMS project — a lightweight, modular PHP content framework derived from OpenCart.
7+
*
8+
* @license GNU General Public License v3.0 (GPL-3.0-or-later)
9+
* @link https://github.com/RandomCoderTinker/Spindle
10+
*/
11+
12+
/** @var Spindle\system\Library\Loggers\Log $log */
13+
/** @var Spindle\system\Library\Http\Response $response */
14+
/** @var Spindle\System\Engine\Registry $registry */
15+
/** @var Spindle\System\Engine\Config $config */
16+
/** @var Spindle\System\Engine\Autoloader $autoloader */
17+
18+
/** @var Spindle\System\Engine\Event $event */
19+
20+
use Spindle\System\Engine\Action;
21+
use Spindle\System\Library\Http\Document;
22+
use Spindle\System\Library\Security\Csp;
23+
use Spindle\System\Library\Security\Csrf;
24+
use Spindle\System\Library\Security\Session;
25+
use Spindle\System\Library\Language\language;
26+
use Spindle\System\Library\Template\Template;
27+
28+
// Include the main autoloader
29+
$autoloader->register('Spindle\\' . ucfirst($config->get('application')) . '\\', $config->get('main_folder'));
30+
die($config->get('main_folder'));
31+
32+
// Include the required vendors for the autoloading shite
33+
require_once(DIR_SYSTEM . 'vendor.php');
34+
35+
// Event Register
36+
if ($config->has('action_event')) {
37+
foreach ($config->get('action_event') as $key => $value) {
38+
foreach ($value as $priority => $action) {
39+
$event->register($key, new Action($action), $priority);
40+
}
41+
}
42+
}
43+
44+
// Set response headers from the config files
45+
foreach ($config->get('response_header') as $header) {
46+
$response->addHeader($header);
47+
}
48+
49+
// CSP headers
50+
$registry->set('csp', new Csp());
51+
$csp = $registry->get('csp');
52+
$csp->generateNonce();
53+
54+
// Set caching headers
55+
$response->addHeader("Cache-Control", "no-store, no-cache, must-revalidate");
56+
$response->addHeader("Pragma", "no-cache");
57+
58+
// Set response compression based on configuration
59+
$response->setCompression((int)$config->get('response_compression'));
60+
61+
// Session Handler
62+
$session = new Session($registry, $config->get('session_expire'));
63+
$registry->set('session', $session);
64+
65+
// Get session parameters from config
66+
$session_name = $config->get('session_name') ?? 'spindle_id';
67+
$session_path = $config->get('session_path') ?? '/';
68+
$session_domain = $config->get('session_domain') ?? '';
69+
$session_expire = $config->get('session_expire') ?? 3600;
70+
$session_samesite = $config->get('session_samesite') ?? 'Strict';
71+
72+
// Set custom session name
73+
session_name($session_name);
74+
75+
// Set session cookie parameters (this auto-sets secure cookie headers)
76+
session_set_cookie_params([
77+
'lifetime' => $session_expire,
78+
'path' => $session_path,
79+
'domain' => $session_domain,
80+
'secure' => TRUE,
81+
'httponly' => TRUE,
82+
'samesite' => $session_samesite,
83+
]);
84+
85+
// Restore session ID from cookie if present
86+
if (isset($request->cookie[$session_name])) {
87+
session_id($request->cookie[$session_name]);
88+
}
89+
90+
// Start the session
91+
$session->start();
92+
93+
// Template
94+
$template = new Template($session);
95+
$template->addPath(MAIN_WEB_ROOT . 'subDomains/' . $config->get('application') . '/view/'); // Default path
96+
$template->addPath('shared', MAIN_WEB_ROOT . 'shared/view/');
97+
$registry->set('template', $template);
98+
99+
// Language
100+
$language = new Language($config->get('language_code'));
101+
$language->addPath(DIR_LANGUAGE);
102+
$language->load('default');
103+
$registry->set('language', $language);
104+
105+
// Document
106+
$registry->set('document', new Document($csp));
107+
108+
// CSRF
109+
$registry->set('csrf', new Csrf($session));
110+
111+
// Finalise the load
112+
require DIR_SYSTEM . 'engine/finalise.php';
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/*
3+
* Spindle CMS
4+
* Copyright (c) 2025. All rights reserved.
5+
*
6+
* This file is part of the Spindle CMS project — a lightweight, modular PHP content framework derived from OpenCart.
7+
*
8+
* @license GNU General Public License v3.0 (GPL-3.0-or-later)
9+
* @link https://github.com/RandomCoderTinker/Spindle
10+
*/
11+
12+
// Get host parts
13+
$host = $_SERVER['HTTP_HOST'] ?? 'localhost';
14+
$host_parts = explode('.', $host);
15+
16+
// Get the first part as subdomain (e.g. docs.spindle.website → docs)
17+
$subdomain = (count($host_parts) >= 3) ? $host_parts[0] : 'default';
18+
19+
// Sanitize: only allow a-z, 0-9, underscore, dash
20+
if (!preg_match('/^[a-z0-9_-]+$/i', $subdomain)) {
21+
$subdomain = 'default';
22+
}
23+
24+
// Set main vars
25+
$_['site_url'] = 'https://' . $subdomain . '.spindle.website/';
26+
$_['application'] = $subdomain;
27+
$_['subdomain'] = $subdomain;
28+
29+
// Folder Route
30+
$_['main_folder'] = MAIN_WEB_ROOT . 'subDomains/' . $subdomain;
31+
32+
// Database
33+
34+
// Response
35+
$_['response_header'] = ['Content-Type: text/html; charset=utf-8'];
36+
$_['response_compression'] = 0;
37+
38+
$_['action_pre_action'] = [];
39+
40+
$_['action_event'] = [
41+
'controller/*/before' => [
42+
0 => 'event/language.before',
43+
],
44+
'controller/*/after' => [
45+
0 => 'event/language.after',
46+
],
47+
'view/*/before' => [
48+
998 => 'event/language',
49+
],
50+
'language/*/after' => [
51+
0 => 'system/language.after',
52+
],
53+
];

0 commit comments

Comments
 (0)