S
S
sl02021-05-05 16:12:34
symfony
sl0, 2021-05-05 16:12:34

How to get cacheDir in an arbitrary class?

I inherited an old bundle with the Excel class, which writes data to a file through PhpOffice\PhpSpreadsheet.
It has the following constructor:

public function __construct(array $options = [])
    {
        $this->cachePath = sys_get_temp_dir().'/excel/excel'.random_int(0, 100000);
        Settings::setCache(new Psr16Cache(new FilesystemAdapter(
            basename($this->cachePath), 3600,  \dirname($this->cachePath)
        )));
        ...

As a result, temporary files go to /tmp of the server and are not deleted. The task is to write the cache to the standard /var/cache/prod/...

The problem is that I cannot add anything to the constructor, because many where the class is called in the form environment variable not everywhere prod. How to get can get cacheDir in this case? $document = new Excel($options);
$this->cachePath = 'var/cache/prod/'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question