| 12345678910111213141516171819202122232425262728293031323334 |
- <?php
- class View {
- protected static $included = [];
- /**
- * @param string $view
- * @param array $params
- * @throws Exception
- */
- public static function include(string $view, array $params = []) {
- $view_path = ROOT_DIR . "/views/" . $view . ".php";
- if(file_exists($view_path)) {
- self::$included[] = $view;
- extract($params);
- /** @noinspection PhpIncludeInspection */
- require $view_path;
- }
- else {
- throw new Exception("View \"$view\" not found");
- }
- }
- /**
- * @param string $view
- * @param array $params
- * @throws Exception
- */
- public static function includeOnce(string $view, array $params = []) {
- if(in_array($view, self::$included)) return;
- self::include($view, $params);
- }
- }
|