This repository has been archived on 2024-07-18. You can view files and clone it, but cannot push or open issues or pull requests.
slim/app/bootstrap.php

40 lines
994 B
PHP
Raw Normal View History

2023-03-10 00:42:07 +00:00
<?php
use Slim\Factory\AppFactory;
use DI\Container as Container;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
require __DIR__ . '/../vendor/autoload.php';
$container = new Container;
$settings = require __DIR__ . '/../app/settings.php';
$settings($container);
// Set view in Container
$container->set('view', function() {
return Twig::create(__DIR__ . '/../templates',
['cache' => __DIR__ . '/../cache']);
});
AppFactory::setContainer($container);
$app = AppFactory::create();
$middleware = require __DIR__ . '/../app/middleware.php';
$middleware($app);
// Routes
$app->get('/', function (Request $request, Response $response, $args) {
$response->getBody()->write("Hello Nick!");
return $response;
});
$app->get('/twig', function (Request $request, Response $response, $args) {
return $this->get('view')->render($response, 'hello.twig', [
'name' => $args['name']
]);
});
$app->run();