<?php

namespace App\Twig;

use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;

class OnlineExtension extends AbstractExtension
{
    private string $projectDir;

    public function __construct(string $projectDir)
    {
        $this->projectDir = $projectDir;
    }

    public function getFunctions(): array
    {
        return [
            new TwigFunction('is_online', [$this, 'isOnline']),
        ];
    }

    public function isOnline(): bool
    {
        return file_exists($this->projectDir . '/var/.online');
    }
}
