boot.php 812 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App;
  3. use Dotenv\Dotenv;
  4. use Dotenv\Exception\ValidationException;
  5. use Exception;
  6. require "vendor/autoload.php";
  7. try {
  8. $dotenv = Dotenv::createImmutable(__DIR__);
  9. $dotenv->load();
  10. $dotenv->required(["DB_HOST", "DB_USERNAME", "DB_PASSWORD", "DB_NAME"]);
  11. $dotenv->required(["DIR_ROOT", "TIMEZONE", "LOCALE", "SESSION_NAME", "ENV"])->notEmpty();
  12. $_ENV["ROOT_DIR"] = __DIR__;
  13. }
  14. catch(ValidationException $e) {
  15. echo $e->getMessage();
  16. exit();
  17. }
  18. try {
  19. Database::connect(
  20. $_ENV["DB_HOST"],
  21. $_ENV["DB_USERNAME"],
  22. $_ENV["DB_PASSWORD"],
  23. $_ENV["DB_NAME"]
  24. );
  25. }
  26. catch(Exception $e) {
  27. View::include("header");
  28. View::include("error", ["message" => "Unable to establish connection to the database. Please try again later."]);
  29. View::include("footer");
  30. exit();
  31. }
  32. chdir($_ENV["ROOT_DIR"]);