add('template', function () { return new \League\Plates\Engine(dirname(__FILE__) . '/templates/', 'php'); }); // Database $dbConfig = require 'config/database.php'; $container->add('database', function () use ($dbConfig) { $dsn = sprintf('mysql:host=%s;dbname=%s;charset=utf8', $dbConfig['host'], $dbConfig['database']); $pdo = new PDO($dsn, $dbConfig['username'], $dbConfig['password']); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); return $pdo; }); // Account Service $container->add('accountService', function () use ($container) { return new AccountService($container->get('database')); }); // Import Rules Service $container->add('importRulesService', function () use ($container) { return new ImportRulesService($container->get('database')); }); // Import Service $container->add('importService', function () use ($container) { return new ImportService($container->get('database')); }); // Budget Service $container->add('budgetService', function () use ($container) { return new BudgetService($container->get('database')); }); // Budget Service $container->add('categoryService', function () use ($container) { return new CategoryService($container->get('database')); }); // Application Setup $app = new Application($container); $request = new Request($_SERVER, $_POST, $_GET, $_FILES ?? [], $_SESSION ?? []); $response = new Response(); if (isset($_SESSION)) { $response->setSession($_SESSION); } $app->handleRequest($request, $response); http_response_code($response->getHttpStatus()); header($response->getContentTypeHeader()); echo $response->getBody();