Link.FYI

Pastebin

Create New My Pastes

Code (PHP) pasted on 2019-01-13, 19:27 Raw Source

  1. <?php
  2.  
  3. use TSHW\NullBudget\Application;
  4. use TSHW\NullBudget\Request;
  5. use TSHW\NullBudget\Response;
  6. use TSHW\NullBudget\Service\AccountService;
  7. use TSHW\NullBudget\Service\BudgetService;
  8. use TSHW\NullBudget\Service\CategoryService;
  9. use TSHW\NullBudget\Service\ImportRulesService;
  10. use TSHW\NullBudget\Service\ImportService;
  11.  
  12. require 'vendor/autoload.php';
  13.  
  14. define('ENV', 'dev');
  15.  
  16. $container = new \League\Container\Container();
  17.  
  18. // Template Engine
  19. $container->add('template', function () {
  20.     return new \League\Plates\Engine(dirname(__FILE__) . '/templates/', 'php');
  21. });
  22.  
  23. // Database
  24. $dbConfig = require 'config/database.php';
  25. $container->add('database', function () use ($dbConfig) {
  26.     $dsn = sprintf('mysql:host=%s;dbname=%s;charset=utf8', $dbConfig['host'], $dbConfig['database']);
  27.     $pdo = new PDO($dsn, $dbConfig['username'], $dbConfig['password']);
  28.     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  29.     $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
  30.     return $pdo;
  31. });
  32.  
  33. // Account Service
  34. $container->add('accountService', function () use ($container) {
  35.     return new AccountService($container->get('database'));
  36. });
  37.  
  38. // Import Rules Service
  39. $container->add('importRulesService', function () use ($container) {
  40.     return new ImportRulesService($container->get('database'));
  41. });
  42.  
  43. // Import Service
  44. $container->add('importService', function () use ($container) {
  45.     return new ImportService($container->get('database'));
  46. });
  47.  
  48. // Budget Service
  49. $container->add('budgetService', function () use ($container) {
  50.     return new BudgetService($container->get('database'));
  51. });
  52.  
  53. // Budget Service
  54. $container->add('categoryService', function () use ($container) {
  55.     return new CategoryService($container->get('database'));
  56. });
  57.  
  58. // Application Setup
  59. $app = new Application($container);
  60.  
  61. $request = new Request($_SERVER, $_POST, $_GET, $_FILES ?? [], $_SESSION ?? []);
  62. $response = new Response();
  63. if (isset($_SESSION)) {
  64.     $response->setSession($_SESSION);
  65. }
  66.  
  67. $app->handleRequest($request, $response);
  68.  
  69. http_response_code($response->getHttpStatus());
  70. header($response->getContentTypeHeader());
  71. echo $response->getBody();
  72.