View.php 582 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace App;
  3. use Exception;
  4. use RuntimeException;
  5. class View {
  6. public static function include(string $name, array $parameters = []): void {
  7. try {
  8. $path = sprintf("%s/views/%s.php", $_ENV["DIR_ROOT"], $name);
  9. if(!file_exists($path)) {
  10. throw new RuntimeException("View '{$name}' not found.");
  11. }
  12. extract($parameters, EXTR_OVERWRITE);
  13. require $path;
  14. }
  15. catch(Exception $e) {
  16. ?>
  17. <div class="alert alert-danger mb-2">
  18. <i class="fa fa-fw fa-exclamation-circle"></i>
  19. <?=htmlspecialchars($e->getMessage())?>
  20. </div>
  21. <?php
  22. }
  23. }
  24. }