From 6af39995f70c15632cb00e67d9ed6339fa641bec Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Thu, 22 Sep 2022 22:17:41 -0400 Subject: [PATCH] Added the hassankhan/config module --- composer.json | 6 +- composer.lock | 319 +++++++++++++++++++++++++++++++++++++++++++-- conf/defaults.json | 3 + src/app.php | 23 +++- src/routes.php | 15 +++ views/index.twig | 1 + 6 files changed, 345 insertions(+), 22 deletions(-) create mode 100644 conf/defaults.json create mode 100644 src/routes.php diff --git a/composer.json b/composer.json index bec5a4a..ba43b78 100644 --- a/composer.json +++ b/composer.json @@ -5,7 +5,7 @@ "license": "BSD-2-Clause", "autoload": { "psr-4": { - "Bitgoblin\\Mcst\\": "src/" + "BitGoblin\\MCST\\": "src/" } }, "authors": [ @@ -17,6 +17,8 @@ "require": { "slim/slim": "^4.10", "slim/psr7": "^1.5", - "slim/twig-view": "^3.3" + "slim/twig-view": "^3.3", + "hassankhan/config": "^3.0", + "php-di/php-di": "^6.4" } } diff --git a/composer.lock b/composer.lock index fa36ba4..18af618 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1d3031cc0afbb5ecb04551cd337c06e6", + "content-hash": "e7cbf8cfe22ea0e64510fe92ffbb4c00", "packages": [ { "name": "fig/http-message-util", @@ -62,6 +62,129 @@ }, "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", "version": "v1.3.0", @@ -113,28 +236,196 @@ "time": "2018-02-13T20:26:39+00:00" }, { - "name": "psr/container", - "version": "2.0.2", + "name": "php-di/invoker", + "version": "2.3.3", "source": { "type": "git", - "url": "https://github.com/php-fig/container.git", - "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963" + "url": "https://github.com/PHP-DI/Invoker.git", + "reference": "cd6d9f267d1a3474bdddf1be1da079f01b942786" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/c71ecc56dfe541dbd90c5360474fbc405f8d5963", - "reference": "c71ecc56dfe541dbd90c5360474fbc405f8d5963", + "url": "https://api.github.com/repos/PHP-DI/Invoker/zipball/cd6d9f267d1a3474bdddf1be1da079f01b942786", + "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": "" }, "require": { "php": ">=7.4.0" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.0.x-dev" - } - }, "autoload": { "psr-4": { "Psr\\Container\\": "src/" @@ -161,9 +452,9 @@ ], "support": { "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", diff --git a/conf/defaults.json b/conf/defaults.json new file mode 100644 index 0000000..af6e59f --- /dev/null +++ b/conf/defaults.json @@ -0,0 +1,3 @@ +{ + "server_directory": "/opt/minecraft" +} diff --git a/src/app.php b/src/app.php index f62e0c5..f4c110e 100644 --- a/src/app.php +++ b/src/app.php @@ -1,12 +1,25 @@ set('config', function() use ($config) { + return $config; +}); + +// Set container to create App with on AppFactory +AppFactory::setContainer($container); $app = AppFactory::create(); // Add Error Handling Middleware @@ -18,7 +31,5 @@ $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'); -}); +// load in route handlers +require_once __DIR__ . '/routes.php'; diff --git a/src/routes.php b/src/routes.php new file mode 100644 index 0000000..3ca485d --- /dev/null +++ b/src/routes.php @@ -0,0 +1,15 @@ +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'); diff --git a/views/index.twig b/views/index.twig index e96a629..5c788ed 100644 --- a/views/index.twig +++ b/views/index.twig @@ -15,6 +15,7 @@

List of servers:

There are currently no servers registered.

+

Home directory: {{ server_dir }}