Code (PHP) pasted on 2019-01-13, 19:27 Raw Source
- <?php
- use TSHW\NullBudget\Application;
- use TSHW\NullBudget\Request;
- use TSHW\NullBudget\Response;
- use TSHW\NullBudget\Service\AccountService;
- use TSHW\NullBudget\Service\BudgetService;
- use TSHW\NullBudget\Service\CategoryService;
- use TSHW\NullBudget\Service\ImportRulesService;
- use TSHW\NullBudget\Service\ImportService;
- require 'vendor/autoload.php';
- $container = new \League\Container\Container();
- // Template Engine
- $container->add('template', function () {
- });
- // Database
- $dbConfig = require 'config/database.php';
- $container->add('database', function () use ($dbConfig) {
- $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();
- $response->setSession($_SESSION);
- }
- $app->handleRequest($request, $response);
- http_response_code($response->getHttpStatus());
- echo $response->getBody();