| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package FirePlugins Framework |
| 4 |
* @version 1.0.1 |
| 5 |
* |
| 6 |
* @author FirePlugins <[email protected]> |
| 7 |
* @link https://www.fireplugins.com |
| 8 |
* @copyright Copyright © 2021 FirePlugins All Rights Reserved |
| 9 |
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later |
| 10 |
*/ |
| 11 |
|
| 12 |
namespace FPFramework\Base; |
| 13 |
|
| 14 |
if (!defined('ABSPATH')) |
| 15 |
{ |
| 16 |
exit; // Exit if accessed directly. |
| 17 |
} |
| 18 |
|
| 19 |
use FPFramework\Libs\Registry; |
| 20 |
|
| 21 |
class Renderer |
| 22 |
{ |
| 23 |
/** |
| 24 |
* Data passed to the view |
| 25 |
* |
| 26 |
* @var mixed |
| 27 |
*/ |
| 28 |
private $data; |
| 29 |
|
| 30 |
private $folder; |
| 31 |
|
| 32 |
private $path_to_layout = ''; |
| 33 |
|
| 34 |
public function __construct($folder) |
| 35 |
{ |
| 36 |
$this->folder = $folder; |
| 37 |
} |
| 38 |
|
| 39 |
public function __get($path_to_layout = '') |
| 40 |
{ |
| 41 |
$this->path_to_layout = $path_to_layout; |
| 42 |
return $this; |
| 43 |
} |
| 44 |
|
| 45 |
/** |
| 46 |
* Renders a layout to the screen |
| 47 |
* |
| 48 |
* @param string $layout |
| 49 |
* @param array $data |
| 50 |
* @param boolean $return |
| 51 |
* |
| 52 |
* @return void |
| 53 |
*/ |
| 54 |
public function render($layout, $data = [], $return = false) |
| 55 |
{ |
| 56 |
$this->data = new Registry($data); |
| 57 |
|
| 58 |
$filename = $this->folder . $this->path_to_layout . '/' . $layout . '.php'; |
| 59 |
|
| 60 |
if (!file_exists($filename)) |
| 61 |
{ |
| 62 |
return; |
| 63 |
} |
| 64 |
|
| 65 |
if ($return) |
| 66 |
{ |
| 67 |
ob_start(); |
| 68 |
include $filename; |
| 69 |
$html = ob_get_contents(); |
| 70 |
ob_end_clean(); |
| 71 |
return $html; |
| 72 |
} |
| 73 |
|
| 74 |
include $filename; |
| 75 |
} |
| 76 |
|
| 77 |
} |