Initial PHP Slim project structure; built a very basic site template

This commit is contained in:
Gregory Ballantine 2022-09-22 20:37:29 -04:00
parent 26a7ab742e
commit 8c15b10389
12 changed files with 1342 additions and 24 deletions

25
.gitignore vendored
View File

@ -1,23 +1,2 @@
# ---> Go # Composer dependencies
# If you prefer the allow list template instead of the deny list, see community template: vendor/
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib
# Test binary, built with `go test -c`
*.test
# Output of the go coverage tool, specifically when used with LiteIDE
*.out
# Dependency directories (remove the comment below to include it)
# vendor/
# Go workspace file
go.work

View File

@ -1,4 +1,4 @@
Copyright (c) <year> <owner> Copyright (c) 2022 Bit Goblin
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

4
bin/run-php.sh Executable file
View File

@ -0,0 +1,4 @@
#!/bin/sh
# start a local instance of the app using PHP's built-in webserver
php -S localhost:8080 -t public/ public/index.php

22
composer.json Normal file
View File

@ -0,0 +1,22 @@
{
"name": "bitgoblin/mcst",
"description": "Minecraft Java Edition server management tool",
"type": "project",
"license": "BSD-2-Clause",
"autoload": {
"psr-4": {
"Bitgoblin\\Mcst\\": "src/"
}
},
"authors": [
{
"name": "Gregory Ballantine",
"email": "gballantine@bitgoblin.tech"
}
],
"require": {
"slim/slim": "^4.10",
"slim/psr7": "^1.5",
"slim/twig-view": "^3.3"
}
}

1159
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

5
public/.htaccess Normal file
View File

@ -0,0 +1,5 @@
# rewrite rules
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

46
public/css/wyrm.css Normal file
View File

@ -0,0 +1,46 @@
body{
background-color: #e6e6e6;
}
/* set the max-width for centered content */
.container{
max-width: 1100px;
}
#main-content{
margin-top: 25px;
padding: 12px 25px;
background: white;
}
/* global navigation bar styles */
.navbar{
padding: 10px 18px;
background-color: #212121;
color: white;
font-size: 2.5rem;
font-weight: bold;
}
.navbar ul{
margin: 0;
padding: 0;
list-style: none;
}
.navbar li{
display: inline-block;
margin-bottom: 0;
}
.navbar li:not(:first-child){
margin-left: 10px;
}
.navbar li>a{
color: #eee;
text-decoration: none;
transition: color 220ms ease-in-out;
}
.navbar li>a:hover{
color: white;
}

24
public/index.php Normal file
View File

@ -0,0 +1,24 @@
<?php
// if we're looking for static files in dev, return false so they can be served.
if (PHP_SAPI == 'cli-server') {
$url = parse_url($_SERVER['REQUEST_URI']);
$file = __DIR__ . $url['path'];
// check the file types, only serve standard files
if (preg_match('/\.(?:png|js|jpg|jpeg|gif|css)$/', $file)) {
// does the file exist? If so, return it
if (is_file($file))
return false;
// file does not exist. return a 404
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found');
printf('"%s" does not exist', $_SERVER['REQUEST_URI']);
return false;
}
}
require_once __DIR__ . '/../src/app.php';
$app->run();

3
public/js/drake.js Normal file
View File

@ -0,0 +1,3 @@
$(document).ready(function () {
// this will be used later.
});

24
src/app.php Normal file
View File

@ -0,0 +1,24 @@
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory;
use Slim\Views\Twig;
use Slim\Views\TwigMiddleware;
require __DIR__ . '/../vendor/autoload.php';
$app = AppFactory::create();
// Add Error Handling Middleware
$app->addErrorMiddleware(true, false, false);
// Create Twig
$twig = Twig::create(__DIR__ . '/../views', ['cache' => false]);
// Add Twig-View Middleware
$app->add(TwigMiddleware::create($app, $twig));
$app->get('/', function (Request $request, Response $response, $args) {
$view = Twig::fromRequest($request);
return $view->render($response, 'index.twig');
});

21
views/index.twig Normal file
View File

@ -0,0 +1,21 @@
{% extends 'layout.twig' %}
{% block content %}
<!-- page header -->
<header class="row">
<div class="columns twelve">
<h1>Welcome to MCST!</h1>
<p>Using MCST you can easily manage your Minecraft: Java Edition servers.</p>
</div>
</header>
<!-- list of servers -->
<section class="row">
<div class="columns twelve">
<h3>List of servers:</h3>
<span><p>There are currently no servers registered.</p></span>
</div>
</section>
{% endblock %}

31
views/layout.twig Normal file
View File

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Minecraft Server Tool</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/skeleton/2.0.4/skeleton.min.css">
<link rel="stylesheet" href="/css/wyrm.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<script src="/js/drake.js"></script>
</head>
<body>
<!-- global navigation -->
<nav class="navbar">
<div class="navbar-left">
<ul>
<li class="menu-text">MCST</li>
<li><a href="/">Home</a></li>
<li><a href="/create">Create</a></li>
<li><a href="/status">Status</a></li>
</ul>
</div>
</nav>
<!-- main content -->
<div id="main-content" class="container">
{% block content %}{% endblock %}
</div>
</body>
</html>