<?php

namespace App;

use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
use Symfony\Component\HttpKernel\Kernel as BaseKernel;

class Kernel extends BaseKernel
{
    use MicroKernelTrait;

    // On read-only-root PaaS (Liara) var/ is not writable, and PHP's default
    // variables_order (GPCS) keeps env vars out of $_SERVER — so in prod, force a
    // writable base (/tmp) directly instead of relying on an env var. Local/dev keep
    // the default var/ paths. APP_CACHE_DIR/APP_LOG_DIR can still override the base.
    private function writableBase(): string
    {
        return $_SERVER['APP_TMP_DIR'] ?? getenv('APP_TMP_DIR') ?: '/tmp/clinicpro';
    }

    public function getCacheDir(): string
    {
        return 'prod' === $this->environment ? $this->writableBase() . '/cache' : parent::getCacheDir();
    }

    public function getLogDir(): string
    {
        return 'prod' === $this->environment ? $this->writableBase() . '/log' : parent::getLogDir();
    }
}
