src/Bundle/Template/Native.php
private function compile(string $name, bool $processLang, bool $processInclude, bool $processExtends): string
    {
        if ($this->isRouteView) {
            $this->isRouteView = false;
            $path = '';
            $stack = debug_backtrace();
            foreach ($stack as $item) {
                if (false !== stripos($item['file'], DIRECTORY_SEPARATOR . 'Route' . DIRECTORY_SEPARATOR)) {
                    $path = pathinfo($item['file'], PATHINFO_DIRNAME) . '/view.html.php';
                    if ($processLang) {
                        $storagePath = str_replace('view.html.php', '_lang/' . $this->language . '.php', $path);
                    }
                    break;
                }
            }
        } else {
            $path = $this->packageRoot . '/view/' . $name;
            if ($processLang) {
                $storagePath = str_replace('view.html.php', '', $path) . '_lang/' . $this->language . '.php';
            }
        }

        if (file_exists($path)) {
            ob_start();
            readfile($path);
            $code = ob_get_clean();
        } else {
            throw new FileNotFoundException($path);
        }

        if ($processLang && file_exists($storagePath)) {
            $storage = include $storagePath;
            if ('' == $this->title) {
                $this->title = $storage['title'] ?? '';
            }
            preg_match_all('/<!-- lang (.*) -->/', $code, $matchList);
            if (isset($matchList[1])) {
                foreach ($matchList[1] as $key => $index) {
                    $name = explode('>', $index);
                    $default = trim($name[1] ?? '');
                    $name = trim($name[0]);
                    if (!empty($matchList[0][$key]) && false !== strpos($code, $matchList[0][$key])) {
                        $code = str_replace($matchList[0][$key], $storage[$name] ?? $default, $code);
                    }
                }
            }
        } else {
            preg_match_all('/<!-- lang (.*) -->/', $code, $matchList);
            if (isset($matchList[1])) {
                foreach ($matchList[1] as $key => $index) {
                    $name = explode('>', $index);
                    $default = trim($name[1] ?? '');
                    $name = trim($name[0]);
                    if (!empty($matchList[0][$key]) && false !== strpos($code, $matchList[0][$key])) {
                        $code = str_replace($matchList[0][$key], $this->$name ?? $default, $code);
                    }
                }
            }
        }

        if ($processInclude) {
            preg_match_all('/<!-- include (.*) -->/', $code, $matchList);
            if (isset($matchList[1])) {
                foreach ($matchList[1] as $key => $template) {
                    if (!empty($matchList[0][$key]) && false !== strpos($code, $matchList[0][$key])) {
                        $template = trim($template);
                        $code = str_replace($matchList[0][$key], $this->compile($template . '/view.html.php', true, true, false), $code);
                    }
                }
            }
        }

        if ($processExtends) {
            preg_match_all('/<!-- extends (.*) -->/', $code, $matchList);
            if (isset($matchList[1][0])) {
                $template = trim($matchList[1][0]);
                $parentHtml = $this->compile($template . '/view.html.php', true, true, false);

                $code = str_replace($matchList[0][0], '', $code);
                $parentHtml = str_replace('<!-- section -->', $code, $parentHtml);
                $code = $parentHtml;
            }
        }

        return $code;
    }
private function compile(string $name, bool $processLang, bool $processInclude, bool $processExtends): string
    {
        if ($this->isRouteView) {
            $this->isRouteView = false;
            $path = '';
            $stack = debug_backtrace();
            foreach ($stack as $item) {
                if (false !== stripos($item['file'], DIRECTORY_SEPARATOR . 'Route' . DIRECTORY_SEPARATOR)) {
                    $path = pathinfo($item['file'], PATHINFO_DIRNAME) . '/view.html.php';
                    if ($processLang) {
                        $storagePath = str_replace('view.html.php', '_lang/' . $this->language . '.php', $path);
                    }
                    break;
                }
            }
        } else {
            $path = $this->packageRoot . '/view/' . $name;
            if ($processLang) {
                $storagePath = str_replace('view.html.php', '', $path) . '_lang/' . $this->language . '.php';
            }
        }

        if (file_exists($path)) {
            ob_start();
            readfile($path);
            $code = ob_get_clean();
        } else {
            throw new FileNotFoundException($path);
        }

        if ($processLang && file_exists($storagePath)) {
            $storage = include $storagePath;
            if ('' == $this->title) {
                $this->title = $storage['title'] ?? '';
            }
            preg_match_all('/<!-- lang (.*) -->/', $code, $matchList);
            if (isset($matchList[1])) {
                foreach ($matchList[1] as $key => $index) {
                    $name = explode('>', $index);
                    $default = trim($name[1] ?? '');
                    $name = trim($name[0]);
                    if (!empty($matchList[0][$key]) && false !== strpos($code, $matchList[0][$key])) {
                        $code = str_replace($matchList[0][$key], $storage[$name] ?? $default, $code);
                    }
                }
            }
        } else {
            preg_match_all('/<!-- lang (.*) -->/', $code, $matchList);
            if (isset($matchList[1])) {
                foreach ($matchList[1] as $key => $index) {
                    $name = explode('>', $index);
                    $default = trim($name[1] ?? '');
                    $name = trim($name[0]);
                    if (!empty($matchList[0][$key]) && false !== strpos($code, $matchList[0][$key])) {
                        $code = str_replace($matchList[0][$key], $this->$name ?? $default, $code);
                    }
                }
            }
        }

        if ($processInclude) {
            preg_match_all('/<!-- include (.*) -->/', $code, $matchList);
            if (isset($matchList[1])) {
                foreach ($matchList[1] as $key => $template) {
                    if (!empty($matchList[0][$key]) && false !== strpos($code, $matchList[0][$key])) {
                        $template = trim($template);
                        $code = str_replace($matchList[0][$key], $this->compile($template . '/view.html.php', true, true, false), $code);
                    }
                }
            }
        }

        if ($processExtends) {
            preg_match_all('/<!-- extends (.*) -->/', $code, $matchList);
            if (isset($matchList[1][0])) {
                $template = trim($matchList[1][0]);
                $parentHtml = $this->compile($template . '/view.html.php', true, true, false);

                $code = str_replace($matchList[0][0], '', $code);
                $parentHtml = str_replace('<!-- section -->', $code, $parentHtml);
                $code = $parentHtml;
            }
        }

        return $code;
    }
Create solid template.

@param string $name
@param bool $processLang
@param bool $processInclude
@param bool $processExtends
@return string
@throws FileNotFoundException