| 1234567891011121314151617181920212223242526272829303132 |
- <?php
- namespace App;
- use Exception;
- use RuntimeException;
- class View {
- public static function include(string $name, array $parameters = []): void {
- try {
- $path = sprintf("%s/views/%s.php", $_ENV["DIR_ROOT"], $name);
- if(!file_exists($path)) {
- throw new RuntimeException("View '{$name}' not found.");
- }
- extract($parameters, EXTR_OVERWRITE);
- require $path;
- }
- catch(Exception $e) {
- ?>
- <div class="alert alert-danger mb-2">
- <i class="fa fa-fw fa-exclamation-circle"></i>
- <?=htmlspecialchars($e->getMessage())?>
- </div>
- <?php
- }
- }
- }
|