| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentForm\Framework\View; |
| 4 |
|
| 5 |
class View |
| 6 |
{ |
| 7 |
protected $app = null; |
| 8 |
|
| 9 |
public function __construct($app) |
| 10 |
{ |
| 11 |
$this->app = $app; |
| 12 |
} |
| 13 |
|
| 14 |
public function make($path, $data = []) |
| 15 |
{ |
| 16 |
$path = str_replace('.', DIRECTORY_SEPARATOR, $path); |
| 17 |
$file = $this->app->viewPath($path).'.php'; |
| 18 |
if (file_exists($file)) { |
| 19 |
ob_start(); |
| 20 |
extract($data); |
| 21 |
include $file; |
| 22 |
return ob_get_clean(); |
| 23 |
} |
| 24 |
|
| 25 |
throw new \InvalidArgumentException("The view file [$file] doesn't exists!"); |
| 26 |
} |
| 27 |
|
| 28 |
public function render($path, $data = []) |
| 29 |
{ |
| 30 |
echo $this->make($path, $data); |
| 31 |
} |
| 32 |
} |