blob: 76c51ed1b29beb41ad6ace9c61966eb76ae680f0 (
plain)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
<?php
// src/view/AbstractBuilder.php
declare(strict_types=1);
use App\Entity\Node;
abstract class AbstractBuilder
{
protected const VIEWS_PATH = '../src/view/templates/';
protected string $html = '';
protected int $id_node;
protected function __construct(Node $node)
{
$this->id_node = $node->getId();
}
protected function useChildrenBuilder(Node $node): void
{
foreach($node->getChildren() as $child_node)
{
$builder_name = $this->snakeToPascalCase($child_node->getName()) . 'Builder';
$builder = new $builder_name($child_node);
$this->html .= $builder->render();
// pages spéciales où on n'assemble pas tout
if($builder_name === 'HeadBuilder' && $builder->getStop())
{
foreach($node->getChildren() as $target_node){
if($target_node->getName() === 'main'){
$main_node = $target_node;
break;
}
}
// on construit <main> et on s'arrête! les autres noeuds sont ignorés
$builder_name = $this->snakeToPascalCase($main_node->getName()) . 'Builder';
$builder = new $builder_name($main_node);
$this->html .= "<body>\n";
$this->html .= $builder->render() . "\n";
$this->html .= "</body>\n</html>";
break;
}
}
}
protected function snakeToPascalCase(string $input): string
{
return str_replace('_', '', ucwords($input, '_'));
}
public function render(): string // = getHTML()
{
return $this->html;
}
public function addHTML(string $html): void
{
$this->html .= $html;
}
}
|