<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use \Symfony\Component\HttpKernel\KernelInterface;


abstract class WebrootController extends AbstractController
{
    private ?string $project_dir = null;
    
    public function __construct(KernelInterface $kernel) 
    {
        $this->project_dir = $kernel->getProjectDir();
    }
    
    public function getHeaderTitleFiglet(): ?string
    {
        $filename = getenv("HEADER_TITLE_FIGLET");
        if (!$filename || !strlen($filename) || !file_exists($filename)) {
            $filename = join(DIRECTORY_SEPARATOR,[dirname(dirname(__DIR__)),"templates","webroot.txt"]);
        }
        $figlet_file = fopen($filename,"r");
        $header_figlet = fread($figlet_file, filesize($filename));
        fclose($figlet_file);
        $title = "<div class=\"center\"><pre>"
                . $header_figlet
                . "</pre></div>";
            return $title;
        return $title;
    }
    
    protected function getControllerVariables(): array
    {
        return [
            "header_title" => $this->getHeaderTitleFiglet(),
        ];      
    }
}
