-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentorno.php
executable file
·41 lines (34 loc) · 1.13 KB
/
entorno.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
require_once 'vendor/autoload.php';
class Entorno{
private $twig;
private $loader;
private static $instancia;
// constructor
private function __construct(){
$this->loader = new \Twig\Loader\FilesystemLoader('templates');
$this->twig = new \Twig\Environment($this->loader,[
'debug' => 'true'
]);
$this->twig->addExtension(new \Twig\Extension\DebugExtension());
}
// no permitir la copia del objeto singleton de la clase
private function __clone(){}
// devuelve la instancia
// si no existe, la crea primero
public static function getInstancia(){
if(!self::$instancia)
self::$instancia = new self();
return self::$instancia;
}
// renderiza un html por completo
public function renderizar($html,$variables){
return $this->twig->render($html,$variables);
}
// renderiza una sección de un html
public function renderizarBloque($html,$bloque,$variables){
$this->template = $this->twig->load($html);
return $this->template->renderBlock($bloque,$variables);
}
}
?>