Added the hassankhan/config module

This commit is contained in:
Gregory Ballantine 2022-09-22 22:17:41 -04:00
parent 8c15b10389
commit 6af39995f7
6 changed files with 345 additions and 22 deletions

View File

@ -5,7 +5,7 @@
"license": "BSD-2-Clause", "license": "BSD-2-Clause",
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Bitgoblin\\Mcst\\": "src/" "BitGoblin\\MCST\\": "src/"
} }
}, },
"authors": [ "authors": [
@ -17,6 +17,8 @@
"require": { "require": {
"slim/slim": "^4.10", "slim/slim": "^4.10",
"slim/psr7": "^1.5", "slim/psr7": "^1.5",
"slim/twig-view": "^3.3" "slim/twig-view": "^3.3",
"hassankhan/config": "^3.0",
"php-di/php-di": "^6.4"
} }
} }

319
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "1d3031cc0afbb5ecb04551cd337c06e6", "content-hash": "e7cbf8cfe22ea0e64510fe92ffbb4c00",
"packages": [ "packages": [
{ {
"name": "fig/http-message-util", "name": "fig/http-message-util",
@ -62,6 +62,129 @@
}, },
"time": "2020-11-24T22:02:12+00:00" "time": "2020-11-24T22:02:12+00:00"
}, },
{
"name": "hassankhan/config",
"version": "3.0.1",
"source": {
"type": "git",
"url": "https://github.com/hassankhan/config.git",
"reference": "82421bb17d21cb0c10b98b89ea54aa4027adfc3f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/hassankhan/config/zipball/82421bb17d21cb0c10b98b89ea54aa4027adfc3f",
"reference": "82421bb17d21cb0c10b98b89ea54aa4027adfc3f",
"shasum": ""
},
"require": {
"php": ">=5.5.9"
},
"require-dev": {
"phpunit/phpunit": "~4.8.36 || ~5.7 || ~6.5 || ~7.5 || ~8.5",
"scrutinizer/ocular": "~1.1",
"squizlabs/php_codesniffer": "~2.2",
"symfony/yaml": "~3.4",
"yoast/phpunit-polyfills": "^1.0"
},
"suggest": {
"symfony/yaml": "~3.4"
},
"type": "library",
"autoload": {
"psr-4": {
"Noodlehaus\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Hassan Khan",
"homepage": "http://hassankhan.me/",
"role": "Developer"
}
],
"description": "Lightweight configuration file loader that supports PHP, INI, XML, JSON, and YAML files",
"homepage": "http://hassankhan.me/config/",
"keywords": [
"config",
"configuration",
"ini",
"json",
"microphp",
"unframework",
"xml",
"yaml",
"yml"
],
"support": {
"issues": "https://github.com/hassankhan/config/issues",
"source": "https://github.com/hassankhan/config/tree/3.0.1"
},
"time": "2022-03-26T19:37:50+00:00"
},
{
"name": "laravel/serializable-closure",
"version": "v1.2.2",
"source": {
"type": "git",
"url": "https://github.com/laravel/serializable-closure.git",
"reference": "47afb7fae28ed29057fdca37e16a84f90cc62fae"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/47afb7fae28ed29057fdca37e16a84f90cc62fae",
"reference": "47afb7fae28ed29057fdca37e16a84f90cc62fae",
"shasum": ""
},
"require": {
"php": "^7.3|^8.0"
},
"require-dev": {
"nesbot/carbon": "^2.61",
"pestphp/pest": "^1.21.3",
"phpstan/phpstan": "^1.8.2",
"symfony/var-dumper": "^5.4.11"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"autoload": {
"psr-4": {
"Laravel\\SerializableClosure\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
},
{
"name": "Nuno Maduro",
"email": "nuno@laravel.com"
}
],
"description": "Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.",
"keywords": [
"closure",
"laravel",
"serializable"
],
"support": {
"issues": "https://github.com/laravel/serializable-closure/issues",
"source": "https://github.com/laravel/serializable-closure"
},
"time": "2022-09-08T13:45:54+00:00"
},
{ {
"name": "nikic/fast-route", "name": "nikic/fast-route",
"version": "v1.3.0", "version": "v1.3.0",
@ -113,28 +236,196 @@
"time": "2018-02-13T20:26:39+00:00" "time": "2018-02-13T20:26:39+00:00"
}, },
{ {
"name": "psr/container", "name": "php-di/invoker",
"version": "2.0.2", "version": "2.3.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/php-fig/container.git", "url": "https://github.com/PHP-DI/Invoker.git",
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" "reference": "cd6d9f267d1a3474bdddf1be1da079f01b942786"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", "url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/cd6d9f267d1a3474bdddf1be1da079f01b942786",
"reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", "reference": "cd6d9f267d1a3474bdddf1be1da079f01b942786",
"shasum": ""
},
"require": {
"php": ">=7.3",
"psr/container": "^1.0|^2.0"
},
"require-dev": {
"athletic/athletic": "~0.1.8",
"mnapoli/hard-mode": "~0.3.0",
"phpunit/phpunit": "^9.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Invoker\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "Generic and extensible callable invoker",
"homepage": "https://github.com/PHP-DI/Invoker",
"keywords": [
"callable",
"dependency",
"dependency-injection",
"injection",
"invoke",
"invoker"
],
"support": {
"issues": "https://github.com/PHP-DI/Invoker/issues",
"source": "https://github.com/PHP-DI/Invoker/tree/2.3.3"
},
"funding": [
{
"url": "https://github.com/mnapoli",
"type": "github"
}
],
"time": "2021-12-13T09:22:56+00:00"
},
{
"name": "php-di/php-di",
"version": "6.4.0",
"source": {
"type": "git",
"url": "https://github.com/PHP-DI/PHP-DI.git",
"reference": "ae0f1b3b03d8b29dff81747063cbfd6276246cc4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHP-DI/PHP-DI/zipball/ae0f1b3b03d8b29dff81747063cbfd6276246cc4",
"reference": "ae0f1b3b03d8b29dff81747063cbfd6276246cc4",
"shasum": ""
},
"require": {
"laravel/serializable-closure": "^1.0",
"php": ">=7.4.0",
"php-di/invoker": "^2.0",
"php-di/phpdoc-reader": "^2.0.1",
"psr/container": "^1.0"
},
"provide": {
"psr/container-implementation": "^1.0"
},
"require-dev": {
"doctrine/annotations": "~1.10",
"friendsofphp/php-cs-fixer": "^2.4",
"mnapoli/phpunit-easymock": "^1.2",
"ocramius/proxy-manager": "^2.11.2",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit": "^9.5"
},
"suggest": {
"doctrine/annotations": "Install it if you want to use annotations (version ~1.2)",
"ocramius/proxy-manager": "Install it if you want to use lazy injection (version ~2.0)"
},
"type": "library",
"autoload": {
"files": [
"src/functions.php"
],
"psr-4": {
"DI\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "The dependency injection container for humans",
"homepage": "https://php-di.org/",
"keywords": [
"PSR-11",
"container",
"container-interop",
"dependency injection",
"di",
"ioc",
"psr11"
],
"support": {
"issues": "https://github.com/PHP-DI/PHP-DI/issues",
"source": "https://github.com/PHP-DI/PHP-DI/tree/6.4.0"
},
"funding": [
{
"url": "https://github.com/mnapoli",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/php-di/php-di",
"type": "tidelift"
}
],
"time": "2022-04-09T16:46:38+00:00"
},
{
"name": "php-di/phpdoc-reader",
"version": "2.2.1",
"source": {
"type": "git",
"url": "https://github.com/PHP-DI/PhpDocReader.git",
"reference": "66daff34cbd2627740ffec9469ffbac9f8c8185c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/PHP-DI/PhpDocReader/zipball/66daff34cbd2627740ffec9469ffbac9f8c8185c",
"reference": "66daff34cbd2627740ffec9469ffbac9f8c8185c",
"shasum": ""
},
"require": {
"php": ">=7.2.0"
},
"require-dev": {
"mnapoli/hard-mode": "~0.3.0",
"phpunit/phpunit": "^8.5|^9.0"
},
"type": "library",
"autoload": {
"psr-4": {
"PhpDocReader\\": "src/PhpDocReader"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"description": "PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules as PHP)",
"keywords": [
"phpdoc",
"reflection"
],
"support": {
"issues": "https://github.com/PHP-DI/PhpDocReader/issues",
"source": "https://github.com/PHP-DI/PhpDocReader/tree/2.2.1"
},
"time": "2020-10-12T12:39:22+00:00"
},
{
"name": "psr/container",
"version": "1.1.2",
"source": {
"type": "git",
"url": "https://github.com/php-fig/container.git",
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea",
"reference": "513e0666f7216c7459170d56df27dfcefe1689ea",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"php": ">=7.4.0" "php": ">=7.4.0"
}, },
"type": "library", "type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"autoload": { "autoload": {
"psr-4": { "psr-4": {
"Psr\\Container\\": "src/" "Psr\\Container\\": "src/"
@ -161,9 +452,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/php-fig/container/issues", "issues": "https://github.com/php-fig/container/issues",
"source": "https://github.com/php-fig/container/tree/2.0.2" "source": "https://github.com/php-fig/container/tree/1.1.2"
}, },
"time": "2021-11-05T16:47:00+00:00" "time": "2021-11-05T16:50:12+00:00"
}, },
{ {
"name": "psr/http-factory", "name": "psr/http-factory",

3
conf/defaults.json Normal file
View File

@ -0,0 +1,3 @@
{
"server_directory": "/opt/minecraft"
}

View File

@ -1,12 +1,25 @@
<?php <?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use DI\Container;
use Noodlehaus\Config;
use Noodlehaus\Parser\Json;
use Slim\Factory\AppFactory; use Slim\Factory\AppFactory;
use Slim\Views\Twig; use Slim\Views\Twig;
use Slim\Views\TwigMiddleware; use Slim\Views\TwigMiddleware;
require __DIR__ . '/../vendor/autoload.php'; require __DIR__ . '/../vendor/autoload.php';
// Load app configuration
$config = Config::load(__DIR__ . '/../conf/defaults.json');
// Create new container object and add our config object to it
$container = new Container();
$container->set('config', function() use ($config) {
return $config;
});
// Set container to create App with on AppFactory
AppFactory::setContainer($container);
$app = AppFactory::create(); $app = AppFactory::create();
// Add Error Handling Middleware // Add Error Handling Middleware
@ -18,7 +31,5 @@ $twig = Twig::create(__DIR__ . '/../views', ['cache' => false]);
// Add Twig-View Middleware // Add Twig-View Middleware
$app->add(TwigMiddleware::create($app, $twig)); $app->add(TwigMiddleware::create($app, $twig));
$app->get('/', function (Request $request, Response $response, $args) { // load in route handlers
$view = Twig::fromRequest($request); require_once __DIR__ . '/routes.php';
return $view->render($response, 'index.twig');
});

15
src/routes.php Normal file
View File

@ -0,0 +1,15 @@
<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Views\Twig;
// index GET route - this page should welcome the user and direct them to the available actions
$app->get('/', function (Request $request, Response $response, $args) {
$config = $this->get('config');
$view = Twig::fromRequest($request);
return $view->render($response, 'index.twig', [
'server_dir' => $config->get('server_directory'),
]);
})->setName('index');

View File

@ -15,6 +15,7 @@
<div class="columns twelve"> <div class="columns twelve">
<h3>List of servers:</h3> <h3>List of servers:</h3>
<span><p>There are currently no servers registered.</p></span> <span><p>There are currently no servers registered.</p></span>
<p>Home directory: {{ server_dir }}</p>
</div> </div>
</section> </section>