Files
tcms/app/bootstrap.php
T
2026-07-04 19:41:44 -04:00

46 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
use NeonBlog\App;
use NeonBlog\CommentService;
use NeonBlog\Config;
use NeonBlog\ContentRepository;
use NeonBlog\Database;
use NeonBlog\Stats;
define('BLOG_ROOT', dirname(__DIR__));
spl_autoload_register(static function (string $class): void {
$prefix = 'NeonBlog\\';
if (strncmp($class, $prefix, strlen($prefix)) !== 0) {
return;
}
$relative = substr($class, strlen($prefix));
$path = BLOG_ROOT . '/app/' . str_replace('\\', '/', $relative) . '.php';
if (is_file($path)) {
require $path;
}
});
if (PHP_SAPI !== 'cli' && session_status() !== PHP_SESSION_ACTIVE) {
session_start([
'cookie_httponly' => true,
'cookie_samesite' => 'Lax',
]);
}
$config = Config::load(BLOG_ROOT . '/config/site.json');
date_default_timezone_set((string) $config->get('timezone', 'UTC'));
$repository = new ContentRepository(
BLOG_ROOT . '/bl-content/pages',
BLOG_ROOT . '/bl-content/databases/pages.json'
);
$pdo = Database::connect(BLOG_ROOT . '/storage/database/blog.sqlite');
$comments = new CommentService($pdo, $config);
$stats = new Stats(BLOG_ROOT . '/storage/stats/visits.csv', $config);
return new App($config, $repository, $comments, $stats);