1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace Juju\App;
- require_once(realpath(dirname(__DIR__).'/Http/Response.class.php'));
- require_once(realpath(dirname(__DIR__).'/Data/template.class.php'));
- use Juju\Data\{Response, Template};
- abstract class View {
- private static $name;
- protected static $template;
- public static function views() : array{
- return array_filter(get_declared_classes(), function($class){
- return 0 === strpos($class, "View\\");
- });
- }
- public static function name() : string{
- if(is_null(static::$name)){
- $name = get_called_class();
- return substr($name, strrpos($name, '\\') + 1);
- }
- return static::$name;
- }
- public static function data(){
- return [
- 'view'=>get_called_class()
- ];
- }
- final public static function render(array $data = []) : string{
- if(is_null(static::$template) && method_exists(get_called_class(), 'setup')){
- static::setup();
- }
- $template = static::$template ?? static::name();
- $data = array_merge(static::data(),$data);
- if(is_string($template)){
- return Template::from($template, $data);
- }elseif(is_array($template)){
- $template = new Template($template['name'], $template['fn']);
- }
- return $template->run($data);
- }
- }
- ?>
|