Doctrine\Common\Annotations\FileCacheReader::saveCacheFile PHP Method

saveCacheFile() private method

Saves the cache file.
private saveCacheFile ( string $path, mixed $data ) : void
$path string
$data mixed
return void
    private function saveCacheFile($path, $data)
    {
        if (!is_writable($this->dir)) {
            throw new \InvalidArgumentException(sprintf('The directory "%s" is not writable. Both, the webserver and the console user need access. You can manage access rights for multiple users with "chmod +a". If your system does not support this, check out the acl package.', $this->dir));
        }
        $tempfile = tempnam($this->dir, uniqid('', true));
        if (false === $tempfile) {
            throw new \RuntimeException(sprintf('Unable to create tempfile in directory: %s', $this->dir));
        }
        @chmod($tempfile, 0666 & ~$this->umask);
        $written = file_put_contents($tempfile, '<?php return unserialize(' . var_export(serialize($data), true) . ');');
        if (false === $written) {
            throw new \RuntimeException(sprintf('Unable to write cached file to: %s', $tempfile));
        }
        @chmod($tempfile, 0666 & ~$this->umask);
        if (false === rename($tempfile, $path)) {
            @unlink($tempfile);
            throw new \RuntimeException(sprintf('Unable to rename %s to %s', $tempfile, $path));
        }
    }