diff options
Diffstat (limited to 'src/view/AbstractBuilder.php')
| -rw-r--r-- | src/view/AbstractBuilder.php | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/src/view/AbstractBuilder.php b/src/view/AbstractBuilder.php deleted file mode 100644 index b9a1d7f..0000000 --- a/src/view/AbstractBuilder.php +++ /dev/null | |||
| @@ -1,77 +0,0 @@ | |||
| 1 | <?php | ||
| 2 | // src/view/AbstractBuilder.php | ||
| 3 | |||
| 4 | declare(strict_types=1); | ||
| 5 | |||
| 6 | use App\Entity\Node; | ||
| 7 | |||
| 8 | abstract class AbstractBuilder | ||
| 9 | { | ||
| 10 | const VIEWS_PATH = '../src/view/templates/'; | ||
| 11 | protected string $html = ''; | ||
| 12 | protected int $id_node; | ||
| 13 | |||
| 14 | protected function __construct(Node $node) | ||
| 15 | { | ||
| 16 | $this->id_node = $node->getId(); | ||
| 17 | } | ||
| 18 | |||
| 19 | protected function useChildrenBuilder(Node $node): void | ||
| 20 | { | ||
| 21 | foreach($node->getChildren() as $child_node) | ||
| 22 | { | ||
| 23 | $builder_name = $this->snakeToPascalCase($child_node->getName()) . 'Builder'; | ||
| 24 | $builder = new $builder_name($child_node); | ||
| 25 | $this->html .= $builder->render(); | ||
| 26 | |||
| 27 | // pages spéciales où on n'assemble pas tout | ||
| 28 | if($builder_name === 'HeadBuilder' && in_array(Model::$page_path->getString(), ['connection', 'user_edit'])) | ||
| 29 | { | ||
| 30 | foreach($node->getChildren() as $target_node){ | ||
| 31 | if($target_node->getName() === 'main'){ | ||
| 32 | $main_node = $target_node; | ||
| 33 | break; | ||
| 34 | } | ||
| 35 | } | ||
| 36 | // on construit <main> et on s'arrête! les autres noeuds sont ignorés | ||
| 37 | $builder_name = $this->snakeToPascalCase($main_node->getName()) . 'Builder'; | ||
| 38 | $builder = new $builder_name($main_node); | ||
| 39 | $this->html .= "<body>\n"; | ||
| 40 | $this->html .= $builder->render() . "\n"; | ||
| 41 | $this->html .= "</body>\n</html>"; | ||
| 42 | break; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | private function snakeToPascalCase(string $input): string | ||
| 48 | { | ||
| 49 | return str_replace('_', '', ucwords($input, '_')); | ||
| 50 | } | ||
| 51 | |||
| 52 | public function render(): string // = getHTML(), nécéssite d'être public | ||
| 53 | { | ||
| 54 | return $this->html; | ||
| 55 | } | ||
| 56 | protected function addHTML(string $html): void | ||
| 57 | { | ||
| 58 | $this->html .= $html; | ||
| 59 | } | ||
| 60 | |||
| 61 | protected function insertSVG(string $path, array $attributes = []): string | ||
| 62 | { | ||
| 63 | $svg = file_get_contents($path); | ||
| 64 | |||
| 65 | // modification des attributs | ||
| 66 | if(!empty($attributes)){ | ||
| 67 | $dom = new DOMDocument(); | ||
| 68 | $dom->loadXML($svg); | ||
| 69 | $svg_elem = $dom->documentElement; | ||
| 70 | foreach($attributes as $key => $value){ | ||
| 71 | $svg_elem->setAttribute($key, $value); | ||
| 72 | } | ||
| 73 | $svg = $dom->saveXML($svg_elem); | ||
| 74 | } | ||
| 75 | return $svg; | ||
| 76 | } | ||
| 77 | } \ No newline at end of file | ||
