Added the hassankhan/config module

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

View File

@ -1,12 +1,25 @@
<?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\Views\Twig;
use Slim\Views\TwigMiddleware;
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();
// 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';