Une erreur est survenue, veuilez contacter le webmaster si cette erreur persiste."; /* (2) Instance constructor * * @view_class The target view class * ---------------------------------------------------------*/ private function __construct(String $view_class){ $this->view_class = $view_class; } /* (3) Renders a view with injected data * * @injected_data Data to inject * * @return render Rendered view * ---------------------------------------------------------*/ public function render($injected_data=[]){ /* (1) Create instance with data */ $view = new $this->view_class(...$injected_data); /* (2) Dispatch rendering */ return $view->render(); } /* (4) Loads a view from its path (builder) * * @view_path View path * * @return view View instance * NULL on error * ---------------------------------------------------------*/ public static function load(String $view_path){ /* (1) Check arguments ---------------------------------------------------------*/ /* (1) Check path format */ if( !preg_match('@^[\w+\.]+$@', $view_path) ) return null; /* (2) Extract class */ $view_class = '\\view\\'.str_replace('.', '\\', $view_path).'\\main'; /* (3) Check if class exists */ if( !class_exists($view_class) ) return null; /* (2) Return View instance ---------------------------------------------------------*/ return new self($view_class); } }