alpha1 #8
9
src/Caddyfile
Normal file
9
src/Caddyfile
Normal file
|
@ -0,0 +1,9 @@
|
|||
{
|
||||
frankenphp
|
||||
order php_server before file_server
|
||||
}
|
||||
http://localhost:8205 {
|
||||
root ./public
|
||||
try_files {uri} {uri}.php
|
||||
php_server
|
||||
}
|
|
@ -9,15 +9,17 @@ class Data {
|
|||
* @return SQLite3 A new connection to the database
|
||||
*/
|
||||
private static function getConnection(): SQLite3 {
|
||||
$db = new SQLite3("../data/{${DATABASE_NAME}}");
|
||||
$db = new SQLite3('../data/' . DATABASE_NAME);
|
||||
$db->exec('PRAGMA foreign_keys = ON;');
|
||||
return $db;
|
||||
}
|
||||
|
||||
public static function ensureDb(): void {
|
||||
$db = self::getConnection();
|
||||
$tables = $db->query("SELECT name FROM sqlite_master WHERE type = 'table'")->fetchArray(SQLITE3_NUM);
|
||||
if (!array_search('frc_user', $tables)) {
|
||||
$tables = array();
|
||||
$tableQuery = $db->query("SELECT name FROM sqlite_master WHERE type = 'table'");
|
||||
while ($table = $tableQuery->fetchArray(SQLITE3_NUM)) $tables[] = $table[0];
|
||||
if (!in_array('frc_user', $tables)) {
|
||||
$query = <<<SQL
|
||||
CREATE TABLE frc_user (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
|
@ -28,7 +30,7 @@ class Data {
|
|||
$db->exec($query);
|
||||
$db->exec('CREATE INDEX idx_user_email ON frc_user (email)');
|
||||
}
|
||||
if (!array_search('feed', $tables)) {
|
||||
if (!in_array('feed', $tables)) {
|
||||
$query = <<<SQL
|
||||
CREATE TABLE feed (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
|
@ -39,7 +41,7 @@ class Data {
|
|||
SQL;
|
||||
$db->exec($query);
|
||||
}
|
||||
if (!array_search('item', $tables)) {
|
||||
if (!in_array('item', $tables)) {
|
||||
$query = <<<SQL
|
||||
CREATE TABLE item (
|
||||
id INTEGER NOT NULL PRIMARY KEY,
|
||||
|
|
8
src/public/index.php
Normal file
8
src/public/index.php
Normal file
|
@ -0,0 +1,8 @@
|
|||
<?php
|
||||
include '../start.php';
|
||||
|
||||
page_head('Welcome');
|
||||
?>
|
||||
<p>Startup worked</p>
|
||||
<?php
|
||||
page_foot();
|
|
@ -18,3 +18,23 @@ const DATABASE_NAME = 'frc.db';
|
|||
// (editing below this line is not advised)
|
||||
|
||||
include 'lib/Data.php';
|
||||
|
||||
/**
|
||||
* Render the page title
|
||||
* @param string $title The title of the page being displayed
|
||||
*/
|
||||
function page_head(string $title): void {
|
||||
?><!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title><?=$title?> | Feed Reader Central</title>
|
||||
</head>
|
||||
<body><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the end of the page
|
||||
*/
|
||||
function page_foot(): void {
|
||||
?></body></html><?php
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user