| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace la_restaurant_theme;
- require_once('renderer.php');
- class view {
- public function __construct(private string $path) {
- if (!$this->exists()) {
- throw new ErrorException('View "'.$path.'" not exists.');
- }
- }
- public function exists(): bool {
- return is_file($this->path);
- }
- private function read(): string {
- $file = fopen($this->path, 'r');
- $size = filesize($this->path);
-
- if ($file === false) {
- throw new ErrorException('View "'.$path.'" is not readable.');
- }
- $content = fread($file, $size);
- fclose($file);
- return $content;
- }
- public function rendering(): renderer {
- static $content = null;
- if ($content === null) {
- $content = $this->read();
- }
- return new renderer($content);
- }
- }
|